2026-04-26 16:14:31 +09:00
|
|
|
package httpapi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"tutor/internal/config"
|
2026-04-26 16:24:35 +09:00
|
|
|
"tutor/internal/interview"
|
2026-04-26 16:34:52 +09:00
|
|
|
"tutor/internal/learnermemory"
|
2026-04-26 16:14:31 +09:00
|
|
|
"tutor/internal/workflows"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestHealth(t *testing.T) {
|
|
|
|
|
cfg := config.Config{
|
|
|
|
|
Environment: "test",
|
|
|
|
|
ModelKey: "deepseek-v4-flash",
|
|
|
|
|
}
|
2026-04-26 16:34:52 +09:00
|
|
|
memory := learnermemory.NewService(learnermemory.NewMemoryStore())
|
|
|
|
|
service := interview.NewService(interview.NewMemoryStore(), workflows.NewStubRunner(), memory)
|
|
|
|
|
handler := NewHandler(cfg, service, memory)
|
2026-04-26 16:14:31 +09:00
|
|
|
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
|
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
|
|
|
|
|
|
handler.Routes().ServeHTTP(rec, req)
|
|
|
|
|
|
|
|
|
|
if rec.Code != http.StatusOK {
|
|
|
|
|
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var body healthResponse
|
|
|
|
|
if err := json.NewDecoder(rec.Body).Decode(&body); err != nil {
|
|
|
|
|
t.Fatalf("decode health response: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if body.Status != "ok" {
|
|
|
|
|
t.Fatalf("body.Status = %q", body.Status)
|
|
|
|
|
}
|
|
|
|
|
if body.Environment != "test" {
|
|
|
|
|
t.Fatalf("body.Environment = %q", body.Environment)
|
|
|
|
|
}
|
|
|
|
|
if body.ModelKey != "deepseek-v4-flash" {
|
|
|
|
|
t.Fatalf("body.ModelKey = %q", body.ModelKey)
|
|
|
|
|
}
|
|
|
|
|
}
|