diff --git a/backend/internal/service/openai_images_incomplete_test.go b/backend/internal/service/openai_images_incomplete_test.go index aa2f92b42d..e707fbf758 100644 --- a/backend/internal/service/openai_images_incomplete_test.go +++ b/backend/internal/service/openai_images_incomplete_test.go @@ -36,9 +36,7 @@ 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)) - if got == nil { - t.Fatal("content_filter incomplete should produce error") - } + require.NotNil(t, got) 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 b1f6152702..3fa88739ad 100644 --- a/backend/internal/service/ops_service_user_error_test.go +++ b/backend/internal/service/ops_service_user_error_test.go @@ -6,6 +6,7 @@ import ( "testing" infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors" + "github.com/stretchr/testify/require" ) type stubOpsRepoForUserErr struct { @@ -119,9 +120,7 @@ func TestGetUserErrorRequestDetail_OwnershipEnforced(t *testing.T) { if err2 != nil { t.Fatalf("expected no error for legitimate access, got %v", err2) } - if got2 == nil { - t.Fatal("expected non-nil detail for legitimate access") - } + require.NotNil(t, got2) 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 c72cf5dbfb..e02842d3d2 100644 --- a/backend/internal/service/ops_user_error_test.go +++ b/backend/internal/service/ops_user_error_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" "time" + + "github.com/stretchr/testify/require" ) func TestMapUserErrorCategory(t *testing.T) { @@ -132,9 +134,7 @@ func TestToUserErrorRequestDetail_WhitelistAndRedacts(t *testing.T) { } out := ToUserErrorRequestDetail(src) - if out == nil { - t.Fatal("expected non-nil detail") - } + require.NotNil(t, out) // 基础字段正确映射 if out.ID != 999 {