diff --git a/backend/internal/service/payment_order_result_test.go b/backend/internal/service/payment_order_result_test.go index e77fbce482..ce405e0a23 100644 --- a/backend/internal/service/payment_order_result_test.go +++ b/backend/internal/service/payment_order_result_test.go @@ -9,6 +9,7 @@ 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) { @@ -389,15 +390,11 @@ func TestMaybeBuildWeChatOAuthRequiredResponse(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - if resp == nil { - t.Fatal("expected oauth_required response, got nil") - } + require.NotNil(t, resp) if resp.ResultType != payment.CreatePaymentResultOAuthRequired { t.Fatalf("result type = %q, want %q", resp.ResultType, payment.CreatePaymentResultOAuthRequired) } - if resp.OAuth == nil { - t.Fatal("expected oauth payload, got nil") - } + require.NotNil(t, resp.OAuth) if resp.OAuth.AppID != "wx123456" { t.Fatalf("appid = %q, want %q", resp.OAuth.AppID, "wx123456") } @@ -503,9 +500,7 @@ func TestMaybeBuildWeChatOAuthRequiredResponseFallsBackToConfiguredLegacySigning if err != nil { t.Fatalf("expected nil error, got %v", err) } - if resp == nil { - t.Fatal("expected oauth-required response, got nil") - } + require.NotNil(t, resp) 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 0e75b4f914..c02ad00e1f 100644 --- a/backend/internal/service/ratelimit_service_anthropic_test.go +++ b/backend/internal/service/ratelimit_service_anthropic_test.go @@ -5,6 +5,8 @@ import ( "strconv" "testing" "time" + + "github.com/stretchr/testify/require" ) func TestCalculateAnthropic429ResetTime_Only5hExceeded(t *testing.T) { @@ -193,9 +195,7 @@ func TestSelectAnthropicFableWindowLimit_RejectedStatus(t *testing.T) { headers.Set("anthropic-ratelimit-unified-7d_oi-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - if limit == nil { - t.Fatal("expected non-nil limit") - } + require.NotNil(t, limit) if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) } @@ -214,9 +214,7 @@ func TestSelectAnthropicFableWindowLimit_UtilizationOnly(t *testing.T) { headers.Set("anthropic-ratelimit-unified-7d_oi-reset", strconv.FormatInt(reset.Unix(), 10)) limit := selectAnthropicFableWindowLimit(headers, now) - if limit == nil { - t.Fatal("expected non-nil limit") - } + require.NotNil(t, limit) if !limit.resetAt.Equal(reset) { t.Errorf("expected resetAt=%v, got %v", reset, limit.resetAt) }