Files
sub2api/backend/internal/repository/account_repo_model_availability_test.go
T
李建琦 6d655c9903
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
2026-08-21 18:30:13 +08:00

59 lines
1.9 KiB
Go

package repository
import (
"context"
"strings"
"testing"
"github.com/DATA-DOG/go-sqlmock"
dbent "github.com/Wei-Shaw/sub2api/ent"
_ "github.com/Wei-Shaw/sub2api/ent/runtime"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/stretchr/testify/require"
"entgo.io/ent/dialect"
entsql "entgo.io/ent/dialect/sql"
)
func TestListModelAvailabilityCandidates_GroupQueryIgnoresTransientState(t *testing.T) {
var capturedSQL string
db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(captureEntQueryMatcher{actual: &capturedSQL}))
require.NoError(t, err)
t.Cleanup(func() { _ = db.Close() })
driver := entsql.OpenDB(dialect.Postgres, db)
client := dbent.NewClient(dbent.Driver(driver))
t.Cleanup(func() { _ = client.Close() })
repo := newAccountRepositoryWithSQL(client, db, nil)
mock.ExpectQuery("model availability candidates").
WillReturnRows(sqlmock.NewRows([]string{"id"}))
groupID := int64(42)
accounts, err := repo.ListModelAvailabilityCandidates(
context.Background(),
&groupID,
[]string{service.PlatformAnthropic},
false,
)
require.NoError(t, err)
require.Empty(t, accounts)
require.NoError(t, mock.ExpectationsWereMet())
normalized := normalizeSQLWhitespace(capturedSQL)
_, whereClause, found := strings.Cut(normalized, " WHERE ")
require.True(t, found, "expected WHERE clause in query: %s", normalized)
whereClause, _, _ = strings.Cut(whereClause, " ORDER BY ")
for _, configuredPredicate := range []string{"group_id", "status", "schedulable", "platform"} {
require.Contains(t, whereClause, configuredPredicate)
}
for _, transientPredicate := range []string{
"rate_limit_reset_at",
"overload_until",
"temp_unschedulable_until",
"expires_at",
"auto_pause_on_expired",
} {
require.NotContains(t, whereClause, transientPredicate, "configured-state diagnosis must not filter transient predicate %q", transientPredicate)
}
}