33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package store
|
|
|
|
import "testing"
|
|
|
|
func TestEffectiveModelRateLimitPolicyTreatsModelRulesAsAuthoritative(t *testing.T) {
|
|
policy := effectiveModelRateLimitPolicy(
|
|
map[string]any{"rules": []any{
|
|
map[string]any{"metric": "rpm", "limit": 500},
|
|
map[string]any{"metric": "tpm_total", "limit": 100000},
|
|
}},
|
|
map[string]any{"rules": []any{
|
|
map[string]any{"metric": "rpm", "limit": 120},
|
|
map[string]any{"metric": "tpm_total", "limit": 240000},
|
|
map[string]any{"metric": "concurrent", "limit": 6},
|
|
}},
|
|
map[string]any{},
|
|
map[string]any{"rules": []any{
|
|
map[string]any{"metric": "rpm", "limit": 30},
|
|
map[string]any{"metric": "concurrent", "limit": 2},
|
|
}},
|
|
)
|
|
|
|
if got := rateLimitForMetric(policy, "rpm"); got != 30 {
|
|
t.Fatalf("expected model rpm limit to win, got %v", got)
|
|
}
|
|
if got := rateLimitForMetric(policy, "concurrent"); got != 2 {
|
|
t.Fatalf("expected model concurrent limit to win, got %v", got)
|
|
}
|
|
if got := rateLimitForMetric(policy, "tpm_total"); got != 0 {
|
|
t.Fatalf("expected missing model tpm limit to mean unlimited, got %v", got)
|
|
}
|
|
}
|