This commit is contained in:
2026-08-17 02:12:17 +08:00
parent 560ae46b82
commit 6a05803e08
96 changed files with 2888 additions and 685 deletions
+29
View File
@@ -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)
}
}