Files
2025-11-25 15:12:31 +08:00

33 lines
1.0 KiB
Go

package handlers_test
import (
"os"
"testing"
)
func TestMain(m *testing.M) {
// Set GO_ENV to test mode before any tests run
// This prevents error_logging from failing when handlers package is imported
os.Setenv("GO_ENV", "development")
// Set other required environment variables for handlers init()
os.Setenv("JWT_SECRET_KEY", "test-secret-key-for-jwt-testing")
os.Setenv("GOOGLE_CLIENT_ID", "test-google-client-id.apps.googleusercontent.com")
os.Setenv("GOOGLE_CLIENT_SECRET", "test-google-client-secret")
os.Setenv("BACKEND_URL", "http://localhost:8080")
os.Setenv("DASHBOARD_URL", "http://localhost:3000")
// Create a temporary .env file if it doesn't exist
// handlers/google_auth.go and handlers/jwt.go have init() that calls godotenv.Load()
// We need to ensure .env exists to prevent log.Fatalf
if _, err := os.Stat(".env"); os.IsNotExist(err) {
// .env should already exist from earlier test setup
// If not, tests may still fail due to handlers init()
}
// Run all tests
exitCode := m.Run()
os.Exit(exitCode)
}