fix test files

This commit is contained in:
2026-01-27 10:45:15 +08:00
parent 8b589e5a55
commit bd0fdf89f3
10 changed files with 83 additions and 72 deletions
+9 -1
View File
@@ -6,12 +6,20 @@ import (
"database/sql"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/DATA-DOG/go-sqlmock"
"github.com/gorilla/mux"
)
func TestMain(m *testing.M) {
os.Setenv("GO_ENV", "development")
code := m.Run()
os.Unsetenv("GO_ENV")
os.Exit(code)
}
func setupMockDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, func()) {
mockDB, mock, err := sqlmock.New()
if err != nil {
@@ -99,7 +107,7 @@ func TestSetupRoutes_AuthCheckEndpoint(t *testing.T) {
if w.Code == http.StatusNotFound {
t.Error("Auth check endpoint should be registered")
}
// Will likely return 401 (no JWT) or 500 (no DB) but that's OK - route exists
if w.Code != http.StatusUnauthorized && w.Code != http.StatusInternalServerError && w.Code != http.StatusForbidden {
t.Logf("Auth check returned status %d (expected 401, 403, or 500 without proper setup)", w.Code)