1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package controlplane
import (
"context"
"testing"
)
func TestGetTenantPreferencesWithoutTenantUsesConfiguredDefault(t *testing.T) {
defaults := BillingPreferenceDefaults{LowBalanceThresholdMicros: 12_500_000, SpendAnomalyMultiplier: 7, SpendAnomalyMinMicros: 8_500_000}
result, err := (&Store{}).GetTenantPreferences(context.Background(), "", defaults)
if err != nil {
t.Fatal(err)
}
if !result.LowBalanceEnabled || result.LowBalanceThresholdMicros != 12_500_000 || !result.SpendAnomalyEnabled ||
result.SpendAnomalyMultiplier != 7 || result.SpendAnomalyMinMicros != 8_500_000 {
t.Fatalf("unexpected defaults: %+v", result)
}
}
func TestPreferenceValidationRejectsUnsafeValuesBeforeDatabaseAccess(t *testing.T) {
store := &Store{}
if _, err := store.SetDeveloperPreferences(context.Background(), SetDeveloperPreferencesInput{
TenantID: "tenant", DefaultModel: "same", FallbackModel: "same",
}, BillingPreferenceDefaults{}); err == nil {
t.Fatal("expected identical default and fallback models to fail")
}
threshold := maxAlertThresholdMicros + 1
if _, err := store.SetBillingPreferences(context.Background(), SetBillingPreferencesInput{
TenantID: "tenant", LowBalanceThresholdMicros: &threshold,
}, BillingPreferenceDefaults{}); err == nil {
t.Fatal("expected excessive low balance threshold to fail")
}
multiplier := int64(1)
if _, err := store.SetBillingPreferences(context.Background(), SetBillingPreferencesInput{
TenantID: "tenant", SpendAnomalyMultiplier: &multiplier,
}, BillingPreferenceDefaults{}); err == nil {
t.Fatal("expected invalid spend anomaly multiplier to fail")
}
}
|