ultisuite-backend/internal/integrationtest/smoke_test.go
R3D347HR4Y fa5394e10d feat(tests): add integration testing framework and configuration
- Introduced a new `.env.test.example` file for integration test configuration.
- Added a `Makefile` to streamline test commands for unit and integration tests.
- Implemented an integration testing harness with support for PostgreSQL, MinIO, and Redis using testcontainers.
- Created a suite of integration tests covering health checks and user management functionalities.
- Enhanced CI workflow to include integration tests with necessary environment variables.
2026-06-07 19:44:29 +02:00

52 lines
1.2 KiB
Go

//go:build integration
package integrationtest
import (
"encoding/json"
"testing"
)
func TestHealthz(t *testing.T) {
h := RequireHarness(t)
resp, err := h.Server.Client().Get(h.Server.URL + "/healthz")
if err != nil {
t.Fatalf("GET /healthz: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 && resp.StatusCode != 503 {
t.Fatalf("status = %d, want 200 or 503", resp.StatusCode)
}
var report map[string]any
if err := json.NewDecoder(resp.Body).Decode(&report); err != nil {
t.Fatalf("decode: %v", err)
}
if report["status"] == nil {
t.Fatalf("missing status field: %#v", report)
}
}
func TestUnauthorizedWithoutToken(t *testing.T) {
h := RequireHarness(t)
client := NewClient(h.Server.URL, "")
resp, err := client.Get("/api/v1/mail/settings")
if err != nil {
t.Fatalf("GET: %v", err)
}
AssertErrorCode(t, resp, 401, "auth.missing_authorization")
}
func TestInvalidToken(t *testing.T) {
h := RequireHarness(t)
client := NewClient(h.Server.URL, "not-a-valid-jwt")
resp, err := client.Get("/api/v1/mail/settings")
if err != nil {
t.Fatalf("GET: %v", err)
}
if resp.Status != 401 {
t.Fatalf("status = %d, want 401; body = %s", resp.Status, string(resp.Body))
}
}