mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 15:38:22 +08:00
chore: remove unrelated test refactors
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user