Cleanup of superseded code that no longer matches the architecture: Removed: - worker-api/ - Cloudflare Worker with D1, superseded by K8s-based matchmaker + direct PostgreSQL - cmd/acb-indexer/ - TypeScript index builder, superseded by Go cmd/acb-index-builder/ - cluster-configuration/ - K8s manifests belong in ardenone-cluster repo Gutted cmd/acb-api/: - Removed registration, job claim/result endpoints (deferred for v1) - Removed dead code: predictions.go, seasons.go, series.go, register.go, jobs.go, glicko2.go - API is now a stub with only health/ready endpoints - Matchmaker and workers handle the core loop without it Updated PROGRESS.md to reflect current architecture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
// newTestServer creates a Server with no database or redis (for unit tests
|
|
// that don't need them).
|
|
func newTestServer() *Server {
|
|
return &Server{
|
|
cfg: Config{
|
|
WorkerAPIKey: "test-key",
|
|
BotTimeoutSecs: 5,
|
|
MaxConsecFails: 3,
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestHealthEndpoint(t *testing.T) {
|
|
srv := newTestServer()
|
|
mux := http.NewServeMux()
|
|
srv.RegisterRoutes(mux)
|
|
|
|
req := httptest.NewRequest("GET", "/health", nil)
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("health status = %d, want 200", w.Code)
|
|
}
|
|
|
|
var body map[string]string
|
|
json.NewDecoder(w.Body).Decode(&body)
|
|
if body["status"] != "ok" {
|
|
t.Errorf("health body = %v, want status=ok", body)
|
|
}
|
|
}
|
|
|
|
func TestWriteJSON(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
writeJSON(w, http.StatusCreated, map[string]string{"key": "value"})
|
|
|
|
if w.Code != http.StatusCreated {
|
|
t.Errorf("status = %d, want 201", w.Code)
|
|
}
|
|
if ct := w.Header().Get("Content-Type"); ct != "application/json" {
|
|
t.Errorf("content-type = %q, want application/json", ct)
|
|
}
|
|
|
|
var body map[string]string
|
|
json.NewDecoder(w.Body).Decode(&body)
|
|
if body["key"] != "value" {
|
|
t.Errorf("body = %v, want key=value", body)
|
|
}
|
|
}
|
|
|
|
func TestWriteError(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
writeError(w, http.StatusBadRequest, "test error")
|
|
|
|
if w.Code != http.StatusBadRequest {
|
|
t.Errorf("status = %d, want 400", w.Code)
|
|
}
|
|
|
|
var body map[string]string
|
|
json.NewDecoder(w.Body).Decode(&body)
|
|
if body["error"] != "test error" {
|
|
t.Errorf("body = %v, want error=test error", body)
|
|
}
|
|
}
|