refactor: rewrite handler-base as Go module
Replace Python handler-base library with Go module providing: - config: environment-based configuration - health: HTTP health/readiness server for k8s probes - natsutil: NATS/JetStream client with msgpack serialization - telemetry: OpenTelemetry tracing and metrics setup - clients: HTTP clients for LLM, embeddings, reranker, STT, TTS - handler: base Handler runner wiring NATS + health + telemetry Implements ADR-0061 Phase 1.
This commit is contained in:
77
health/health_test.go
Normal file
77
health/health_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHealthEndpoint(t *testing.T) {
|
||||
srv := New(18080, "/health", "/ready", nil)
|
||||
srv.Start()
|
||||
defer srv.Stop(context.Background())
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
resp, err := http.Get("http://localhost:18080/health")
|
||||
if err != nil {
|
||||
t.Fatalf("health request failed: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("expected 200, got %d", resp.StatusCode)
|
||||
}
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
var data map[string]string
|
||||
_ = json.Unmarshal(body, &data)
|
||||
if data["status"] != "healthy" {
|
||||
t.Errorf("expected status 'healthy', got %q", data["status"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadyEndpointDefault(t *testing.T) {
|
||||
srv := New(18081, "/health", "/ready", nil)
|
||||
srv.Start()
|
||||
defer srv.Stop(context.Background())
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
resp, err := http.Get("http://localhost:18081/ready")
|
||||
if err != nil {
|
||||
t.Fatalf("ready request failed: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
t.Errorf("expected 200, got %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadyEndpointNotReady(t *testing.T) {
|
||||
ready := false
|
||||
srv := New(18082, "/health", "/ready", func() bool { return ready })
|
||||
srv.Start()
|
||||
defer srv.Stop(context.Background())
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
resp, err := http.Get("http://localhost:18082/ready")
|
||||
if err != nil {
|
||||
t.Fatalf("ready request failed: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 503 {
|
||||
t.Errorf("expected 503 when not ready, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
ready = true
|
||||
resp2, err := http.Get("http://localhost:18082/ready")
|
||||
if err != nil {
|
||||
t.Fatalf("ready request failed: %v", err)
|
||||
}
|
||||
resp2.Body.Close()
|
||||
if resp2.StatusCode != 200 {
|
||||
t.Errorf("expected 200 when ready, got %d", resp2.StatusCode)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user