mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
sdk/cliproxy/auth: update selector tests
This commit is contained in:
62
sdk/cliproxy/auth/conductor_availability_test.go
Normal file
62
sdk/cliproxy/auth/conductor_availability_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestUpdateAggregatedAvailability_UnavailableWithoutNextRetryDoesNotBlockAuth(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
now := time.Now()
|
||||
model := "test-model"
|
||||
auth := &Auth{
|
||||
ID: "a",
|
||||
ModelStates: map[string]*ModelState{
|
||||
model: {
|
||||
Status: StatusError,
|
||||
Unavailable: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
updateAggregatedAvailability(auth, now)
|
||||
|
||||
if auth.Unavailable {
|
||||
t.Fatalf("auth.Unavailable = true, want false")
|
||||
}
|
||||
if !auth.NextRetryAfter.IsZero() {
|
||||
t.Fatalf("auth.NextRetryAfter = %v, want zero", auth.NextRetryAfter)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateAggregatedAvailability_FutureNextRetryBlocksAuth(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
now := time.Now()
|
||||
model := "test-model"
|
||||
next := now.Add(5 * time.Minute)
|
||||
auth := &Auth{
|
||||
ID: "a",
|
||||
ModelStates: map[string]*ModelState{
|
||||
model: {
|
||||
Status: StatusError,
|
||||
Unavailable: true,
|
||||
NextRetryAfter: next,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
updateAggregatedAvailability(auth, now)
|
||||
|
||||
if !auth.Unavailable {
|
||||
t.Fatalf("auth.Unavailable = false, want true")
|
||||
}
|
||||
if auth.NextRetryAfter.IsZero() {
|
||||
t.Fatalf("auth.NextRetryAfter = zero, want %v", next)
|
||||
}
|
||||
if auth.NextRetryAfter.Sub(next) > time.Second || next.Sub(auth.NextRetryAfter) > time.Second {
|
||||
t.Fatalf("auth.NextRetryAfter = %v, want %v", auth.NextRetryAfter, next)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user