From e087f1b73699d31a1077b03e10dae0e8c3992a9c Mon Sep 17 00:00:00 2001 From: wucm667 Date: Thu, 30 Jul 2026 00:49:48 +0800 Subject: [PATCH] fix(lint): use fatal pointer assertions in usage tests --- .../internal/service/account_usage_service_test.go | 14 +++++--------- .../service/ratelimit_service_anthropic_test.go | 4 +--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/backend/internal/service/account_usage_service_test.go b/backend/internal/service/account_usage_service_test.go index ca153a3c4..6d7fa8fb5 100644 --- a/backend/internal/service/account_usage_service_test.go +++ b/backend/internal/service/account_usage_service_test.go @@ -5,6 +5,8 @@ import ( "net/http" "testing" "time" + + "github.com/stretchr/testify/require" ) type accountUsageCodexProbeRepo struct { @@ -216,9 +218,7 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_5h_reset_at": "2026-03-16T10:00:00Z", // 2h ago } progress := buildCodexUsageProgressFromExtra(extra, "5h", now) - if progress == nil { - t.Fatal("expected non-nil progress") - } + require.NotNil(t, progress) if progress.Utilization != 0 { t.Fatalf("expected Utilization=0 for expired window, got %v", progress.Utilization) } @@ -234,9 +234,7 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_5h_reset_at": resetAt, } progress := buildCodexUsageProgressFromExtra(extra, "5h", now) - if progress == nil { - t.Fatal("expected non-nil progress") - } + require.NotNil(t, progress) if progress.Utilization != 42.0 { t.Fatalf("expected Utilization=42, got %v", progress.Utilization) } @@ -248,9 +246,7 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_7d_reset_at": "2026-03-15T00:00:00Z", // yesterday } progress := buildCodexUsageProgressFromExtra(extra, "7d", now) - if progress == nil { - t.Fatal("expected non-nil progress") - } + require.NotNil(t, progress) if progress.Utilization != 0 { t.Fatalf("expected Utilization=0 for expired 7d window, got %v", progress.Utilization) } diff --git a/backend/internal/service/ratelimit_service_anthropic_test.go b/backend/internal/service/ratelimit_service_anthropic_test.go index c02ad00e1..0755a0256 100644 --- a/backend/internal/service/ratelimit_service_anthropic_test.go +++ b/backend/internal/service/ratelimit_service_anthropic_test.go @@ -248,9 +248,7 @@ func TestSelectAnthropicFableWindowLimit_FallsBackToAggregateReset(t *testing.T) headers.Set("anthropic-ratelimit-unified-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - if limit == nil { - t.Fatal("expected non-nil limit via aggregate reset fallback") - } + require.NotNil(t, limit) if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) }