mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-11 14:47:58 +08:00
- Added support for weighted round-robin authentication scheduling strategy. - Implemented credential weight validation for attributes and metadata, with strict error handling for invalid weights. - Enhanced scheduler with smooth weighted state handling and proportional selection logic. - Introduced tests for credential weight parsing, validation, and weighted round-robin behavior. - Updated configuration to include `weight` field for credentials with range validation. Closes: #4470
33 lines
889 B
Go
33 lines
889 B
Go
package cliproxy
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
internalconfig "github.com/router-for-me/CLIProxyAPI/v7/internal/config"
|
|
)
|
|
|
|
func TestBuilderBuildRejectsInvalidWithConfigCredentialWeight(t *testing.T) {
|
|
invalidWeight := internalconfig.MaxCredentialWeight + 1
|
|
cfg := &internalconfig.Config{
|
|
ClaudeKey: []internalconfig.ClaudeKey{{
|
|
APIKey: "claude-key",
|
|
Weight: &invalidWeight,
|
|
}},
|
|
}
|
|
|
|
service, errBuild := NewBuilder().
|
|
WithConfig(cfg).
|
|
WithConfigPath(t.TempDir() + "/config.yaml").
|
|
Build()
|
|
if errBuild == nil {
|
|
t.Fatal("Build() accepted an invalid credential weight")
|
|
}
|
|
if service != nil {
|
|
t.Fatal("Build() returned a service for an invalid credential weight")
|
|
}
|
|
if !strings.Contains(errBuild.Error(), "cliproxy: validate credential weights: claude-api-key[0].weight") {
|
|
t.Fatalf("Build() error = %q, want contextual credential weight path", errBuild)
|
|
}
|
|
}
|