mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-21 06:56:58 +00:00
fix(lint): use require.NotNil for staticcheck SA5011
Replace if-then-t.Fatal nil checks with testify require.NotNil so staticcheck can prove the pointer is non-nil before field access. Fixes SA5011 in payment_handler_test, parse_test, and openai_images_incomplete_test.
This commit is contained in:
@@ -8,6 +8,7 @@ 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) {
|
||||
@@ -32,9 +33,7 @@ func TestSanitizeAdminPaymentOrderForResponseAddsCurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
got := sanitizeAdminPaymentOrderForResponse(order)
|
||||
if got == nil {
|
||||
t.Fatal("expected sanitized order")
|
||||
}
|
||||
require.NotNil(t, got)
|
||||
if got.Currency != "USD" {
|
||||
t.Fatalf("expected currency USD, got %q", got.Currency)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package proxyurl
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParse_空字符串直连(t *testing.T) {
|
||||
@@ -39,9 +41,7 @@ func TestParse_有效HTTP代理(t *testing.T) {
|
||||
if trimmed != "http://proxy.example.com:8080" {
|
||||
t.Errorf("trimmed 不匹配: got %q", trimmed)
|
||||
}
|
||||
if parsed == nil {
|
||||
t.Fatal("parsed 不应为 nil")
|
||||
}
|
||||
require.NotNil(t, parsed)
|
||||
if parsed.Host != "proxy.example.com:8080" {
|
||||
t.Errorf("Host 不匹配: got %q", parsed.Host)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// response.incomplete(生成超时/截断)应被识别为可重试的 502 上游错误,触发 failover。
|
||||
@@ -16,9 +17,7 @@ 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))
|
||||
if got == nil {
|
||||
t.Fatal("incomplete event should produce an upstream error, got nil")
|
||||
}
|
||||
require.NotNil(t, got)
|
||||
if got.StatusCode != http.StatusBadGateway {
|
||||
t.Fatalf("incomplete(max_output_tokens) should be 502 retryable, got %d", got.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user