From c91fbeb0c008b2323e98ca5b73cedf074c8543dd Mon Sep 17 00:00:00 2001 From: wucm667 Date: Tue, 11 Aug 2026 16:01:06 +0800 Subject: [PATCH] chore: remove unrelated test refactors --- .../internal/handler/admin/payment_handler_test.go | 5 +++-- backend/internal/pkg/proxyurl/parse_test.go | 6 +++--- .../internal/service/account_usage_service_test.go | 14 +++++++++----- .../service/gemini_messages_compat_service_test.go | 4 +++- .../openai_gateway_service_codex_snapshot_test.go | 10 ++++++---- .../service/openai_images_incomplete_test.go | 9 ++++++--- .../service/ops_service_user_error_test.go | 5 +++-- backend/internal/service/ops_user_error_test.go | 6 +++--- .../internal/service/payment_order_result_test.go | 13 +++++++++---- .../service/ratelimit_service_anthropic_test.go | 14 +++++++++----- 10 files changed, 54 insertions(+), 32 deletions(-) diff --git a/backend/internal/handler/admin/payment_handler_test.go b/backend/internal/handler/admin/payment_handler_test.go index c72132382f..d0752ec09a 100644 --- a/backend/internal/handler/admin/payment_handler_test.go +++ b/backend/internal/handler/admin/payment_handler_test.go @@ -8,7 +8,6 @@ import ( dbent "github.com/Wei-Shaw/sub2api/ent" "github.com/Wei-Shaw/sub2api/internal/service" - "github.com/stretchr/testify/require" ) func TestSanitizeAdminPaymentOrderForResponseAddsCurrency(t *testing.T) { @@ -33,7 +32,9 @@ func TestSanitizeAdminPaymentOrderForResponseAddsCurrency(t *testing.T) { } got := sanitizeAdminPaymentOrderForResponse(order) - require.NotNil(t, got) + if got == nil { + t.Fatal("expected sanitized order") + } if got.Currency != "USD" { t.Fatalf("expected currency USD, got %q", got.Currency) } diff --git a/backend/internal/pkg/proxyurl/parse_test.go b/backend/internal/pkg/proxyurl/parse_test.go index 05fde1284d..5fb57c16f7 100644 --- a/backend/internal/pkg/proxyurl/parse_test.go +++ b/backend/internal/pkg/proxyurl/parse_test.go @@ -3,8 +3,6 @@ package proxyurl import ( "strings" "testing" - - "github.com/stretchr/testify/require" ) func TestParse_空字符串直连(t *testing.T) { @@ -41,7 +39,9 @@ func TestParse_有效HTTP代理(t *testing.T) { if trimmed != "http://proxy.example.com:8080" { t.Errorf("trimmed 不匹配: got %q", trimmed) } - require.NotNil(t, parsed) + if parsed == nil { + t.Fatal("parsed 不应为 nil") + } if parsed.Host != "proxy.example.com:8080" { t.Errorf("Host 不匹配: got %q", parsed.Host) } diff --git a/backend/internal/service/account_usage_service_test.go b/backend/internal/service/account_usage_service_test.go index 6d7fa8fb5f..ca153a3c42 100644 --- a/backend/internal/service/account_usage_service_test.go +++ b/backend/internal/service/account_usage_service_test.go @@ -5,8 +5,6 @@ import ( "net/http" "testing" "time" - - "github.com/stretchr/testify/require" ) type accountUsageCodexProbeRepo struct { @@ -218,7 +216,9 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_5h_reset_at": "2026-03-16T10:00:00Z", // 2h ago } progress := buildCodexUsageProgressFromExtra(extra, "5h", now) - require.NotNil(t, progress) + if progress == nil { + t.Fatal("expected non-nil progress") + } if progress.Utilization != 0 { t.Fatalf("expected Utilization=0 for expired window, got %v", progress.Utilization) } @@ -234,7 +234,9 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_5h_reset_at": resetAt, } progress := buildCodexUsageProgressFromExtra(extra, "5h", now) - require.NotNil(t, progress) + if progress == nil { + t.Fatal("expected non-nil progress") + } if progress.Utilization != 42.0 { t.Fatalf("expected Utilization=42, got %v", progress.Utilization) } @@ -246,7 +248,9 @@ func TestBuildCodexUsageProgressFromExtra_ZerosExpiredWindow(t *testing.T) { "codex_7d_reset_at": "2026-03-15T00:00:00Z", // yesterday } progress := buildCodexUsageProgressFromExtra(extra, "7d", now) - require.NotNil(t, progress) + if progress == nil { + t.Fatal("expected non-nil progress") + } if progress.Utilization != 0 { t.Fatalf("expected Utilization=0 for expired 7d window, got %v", progress.Utilization) } diff --git a/backend/internal/service/gemini_messages_compat_service_test.go b/backend/internal/service/gemini_messages_compat_service_test.go index acf9075c54..59f83a6835 100644 --- a/backend/internal/service/gemini_messages_compat_service_test.go +++ b/backend/internal/service/gemini_messages_compat_service_test.go @@ -782,7 +782,9 @@ func TestExtractGeminiUsage(t *testing.T) { } return } - require.NotNil(t, got) + if got == nil { + t.Fatalf("期望返回非 nil,实际返回 nil") + } if got.InputTokens != tt.wantUsage.InputTokens { t.Errorf("InputTokens: 期望 %d,实际 %d", tt.wantUsage.InputTokens, got.InputTokens) } diff --git a/backend/internal/service/openai_gateway_service_codex_snapshot_test.go b/backend/internal/service/openai_gateway_service_codex_snapshot_test.go index 59568b33c9..27208b58d9 100644 --- a/backend/internal/service/openai_gateway_service_codex_snapshot_test.go +++ b/backend/internal/service/openai_gateway_service_codex_snapshot_test.go @@ -3,8 +3,6 @@ package service import ( "testing" "time" - - "github.com/stretchr/testify/require" ) func TestCodexSnapshotBaseTime(t *testing.T) { @@ -52,7 +50,9 @@ func TestCodexResetAtRFC3339(t *testing.T) { t.Run("positive seconds", func(t *testing.T) { sec := 90 got := codexResetAtRFC3339(base, &sec) - require.NotNil(t, got) + if got == nil { + t.Fatal("expected non-nil") + } if *got != "2026-02-16T10:01:30Z" { t.Fatalf("got %s, want %s", *got, "2026-02-16T10:01:30Z") } @@ -61,7 +61,9 @@ func TestCodexResetAtRFC3339(t *testing.T) { t.Run("negative seconds clamp to base", func(t *testing.T) { sec := -3 got := codexResetAtRFC3339(base, &sec) - require.NotNil(t, got) + if got == nil { + t.Fatal("expected non-nil") + } if *got != "2026-02-16T10:00:00Z" { t.Fatalf("got %s, want %s", *got, "2026-02-16T10:00:00Z") } diff --git a/backend/internal/service/openai_images_incomplete_test.go b/backend/internal/service/openai_images_incomplete_test.go index e707fbf758..6a8ba56225 100644 --- a/backend/internal/service/openai_images_incomplete_test.go +++ b/backend/internal/service/openai_images_incomplete_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/gin-gonic/gin" - "github.com/stretchr/testify/require" ) // response.incomplete(生成超时/截断)应被识别为可重试的 502 上游错误,触发 failover。 @@ -17,7 +16,9 @@ func TestExtractImagesUpstreamError_IncompleteIsRetryable(t *testing.T) { body := "data: {\"type\":\"response.created\",\"response\":{\"id\":\"resp_1\"}}\n\n" + "data: {\"type\":\"response.incomplete\",\"response\":{\"id\":\"resp_1\",\"status\":\"incomplete\",\"incomplete_details\":{\"reason\":\"max_output_tokens\"}}}\n\n" got := extractOpenAIImagesUpstreamError([]byte(body)) - require.NotNil(t, got) + if got == nil { + t.Fatal("incomplete event should produce an upstream error, got nil") + } if got.StatusCode != http.StatusBadGateway { t.Fatalf("incomplete(max_output_tokens) should be 502 retryable, got %d", got.StatusCode) } @@ -36,7 +37,9 @@ func TestExtractImagesUpstreamError_IncompleteIsRetryable(t *testing.T) { func TestExtractImagesUpstreamError_IncompleteContentFilterNotRetryable(t *testing.T) { body := "data: {\"type\":\"response.incomplete\",\"response\":{\"id\":\"r\",\"status\":\"incomplete\",\"incomplete_details\":{\"reason\":\"content_filter\"}}}\n\n" got := extractOpenAIImagesUpstreamError([]byte(body)) - require.NotNil(t, got) + if got == nil { + t.Fatal("content_filter incomplete should produce error") + } if got.StatusCode != http.StatusBadRequest { t.Fatalf("content_filter should be 400 (non-retryable), got %d", got.StatusCode) } diff --git a/backend/internal/service/ops_service_user_error_test.go b/backend/internal/service/ops_service_user_error_test.go index 3fa88739ad..b1f6152702 100644 --- a/backend/internal/service/ops_service_user_error_test.go +++ b/backend/internal/service/ops_service_user_error_test.go @@ -6,7 +6,6 @@ import ( "testing" infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors" - "github.com/stretchr/testify/require" ) type stubOpsRepoForUserErr struct { @@ -120,7 +119,9 @@ func TestGetUserErrorRequestDetail_OwnershipEnforced(t *testing.T) { if err2 != nil { t.Fatalf("expected no error for legitimate access, got %v", err2) } - require.NotNil(t, got2) + if got2 == nil { + t.Fatal("expected non-nil detail for legitimate access") + } if got2.ID != 42 { t.Errorf("want ID=42, got %d", got2.ID) } diff --git a/backend/internal/service/ops_user_error_test.go b/backend/internal/service/ops_user_error_test.go index e02842d3d2..c72cf5dbfb 100644 --- a/backend/internal/service/ops_user_error_test.go +++ b/backend/internal/service/ops_user_error_test.go @@ -5,8 +5,6 @@ import ( "strings" "testing" "time" - - "github.com/stretchr/testify/require" ) func TestMapUserErrorCategory(t *testing.T) { @@ -134,7 +132,9 @@ func TestToUserErrorRequestDetail_WhitelistAndRedacts(t *testing.T) { } out := ToUserErrorRequestDetail(src) - require.NotNil(t, out) + if out == nil { + t.Fatal("expected non-nil detail") + } // 基础字段正确映射 if out.ID != 999 { diff --git a/backend/internal/service/payment_order_result_test.go b/backend/internal/service/payment_order_result_test.go index ce405e0a23..e77fbce482 100644 --- a/backend/internal/service/payment_order_result_test.go +++ b/backend/internal/service/payment_order_result_test.go @@ -9,7 +9,6 @@ import ( dbent "github.com/Wei-Shaw/sub2api/ent" "github.com/Wei-Shaw/sub2api/internal/payment" infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors" - "github.com/stretchr/testify/require" ) func TestShouldUseAlipayMobilePrecreate(t *testing.T) { @@ -390,11 +389,15 @@ func TestMaybeBuildWeChatOAuthRequiredResponse(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - require.NotNil(t, resp) + if resp == nil { + t.Fatal("expected oauth_required response, got nil") + } if resp.ResultType != payment.CreatePaymentResultOAuthRequired { t.Fatalf("result type = %q, want %q", resp.ResultType, payment.CreatePaymentResultOAuthRequired) } - require.NotNil(t, resp.OAuth) + if resp.OAuth == nil { + t.Fatal("expected oauth payload, got nil") + } if resp.OAuth.AppID != "wx123456" { t.Fatalf("appid = %q, want %q", resp.OAuth.AppID, "wx123456") } @@ -500,7 +503,9 @@ func TestMaybeBuildWeChatOAuthRequiredResponseFallsBackToConfiguredLegacySigning if err != nil { t.Fatalf("expected nil error, got %v", err) } - require.NotNil(t, resp) + if resp == nil { + t.Fatal("expected oauth-required response, got nil") + } if resp.ResultType != payment.CreatePaymentResultOAuthRequired { t.Fatalf("result type = %q, want %q", resp.ResultType, payment.CreatePaymentResultOAuthRequired) } diff --git a/backend/internal/service/ratelimit_service_anthropic_test.go b/backend/internal/service/ratelimit_service_anthropic_test.go index 0755a02565..0e75b4f914 100644 --- a/backend/internal/service/ratelimit_service_anthropic_test.go +++ b/backend/internal/service/ratelimit_service_anthropic_test.go @@ -5,8 +5,6 @@ import ( "strconv" "testing" "time" - - "github.com/stretchr/testify/require" ) func TestCalculateAnthropic429ResetTime_Only5hExceeded(t *testing.T) { @@ -195,7 +193,9 @@ func TestSelectAnthropicFableWindowLimit_RejectedStatus(t *testing.T) { headers.Set("anthropic-ratelimit-unified-7d_oi-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - require.NotNil(t, limit) + if limit == nil { + t.Fatal("expected non-nil limit") + } if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) } @@ -214,7 +214,9 @@ func TestSelectAnthropicFableWindowLimit_UtilizationOnly(t *testing.T) { headers.Set("anthropic-ratelimit-unified-7d_oi-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - require.NotNil(t, limit) + if limit == nil { + t.Fatal("expected non-nil limit") + } if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) } @@ -248,7 +250,9 @@ func TestSelectAnthropicFableWindowLimit_FallsBackToAggregateReset(t *testing.T) headers.Set("anthropic-ratelimit-unified-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - require.NotNil(t, limit) + if limit == nil { + t.Fatal("expected non-nil limit via aggregate reset fallback") + } if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) }