优化
This commit is contained in:
@@ -81,3 +81,32 @@ func TestUpdateSecurityDoesNotBackfillWithoutDisabledToEnabledTransition(t *test
|
||||
t.Fatalf("call order = %v, want [get save]", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecurityReadsPersistedValueWhileCurrentUsesCache(t *testing.T) {
|
||||
repo := &securityUpdateRepo{current: &SecurityConfig{ID: 1, LimitCount: 10}}
|
||||
uc := NewSecurityUsecase(repo, nil, nil, nil)
|
||||
|
||||
cached, err := uc.Current(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cached.LimitCount != 10 {
|
||||
t.Fatalf("initial cached limit = %d", cached.LimitCount)
|
||||
}
|
||||
repo.current.LimitCount = 20
|
||||
|
||||
current, err := uc.Current(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if current.LimitCount != 10 {
|
||||
t.Fatalf("Current() bypassed cache: %d", current.LimitCount)
|
||||
}
|
||||
fresh, err := uc.Security(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fresh.LimitCount != 20 {
|
||||
t.Fatalf("Security() returned stale value: %d", fresh.LimitCount)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user