Files
Luminary/internal/balancer/weighted_test.go
T
renjue 76ba500417
CI / docker (push) Successful in 2m4s
Initial commit: Luminary AI Gateway
OpenAI-compatible AI gateway with Vue admin UI, multi-provider egress,
ingress key governance, monitoring, and security controls.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 21:46:16 +08:00

33 lines
742 B
Go

package balancer_test
import (
"testing"
"github.com/rose_cat707/luminary/internal/balancer"
"github.com/rose_cat707/luminary/internal/model"
)
func TestSelectWeighted(t *testing.T) {
candidates := []balancer.KeyCandidate{
{Key: model.ProviderKey{ID: 1, Name: "a"}, Weight: 1},
{Key: model.ProviderKey{ID: 2, Name: "b"}, Weight: 3},
}
counts := map[uint]int{}
for i := 0; i < 1000; i++ {
k := balancer.SelectWeighted(candidates)
if k == nil {
t.Fatal("nil key")
}
counts[k.ID]++
}
if counts[2] <= counts[1] {
t.Fatalf("expected heavier weight key selected more often: %v", counts)
}
}
func TestSelectWeightedEmpty(t *testing.T) {
if k := balancer.SelectWeighted(nil); k != nil {
t.Fatal("expected nil")
}
}