Ergaenze HTTP-Tests fuer Basisendpunkte
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
ef657997b2
commit
ad3d4316b6
1 changed files with 130 additions and 0 deletions
130
server/backend/internal/httpapi/router_test.go
Normal file
130
server/backend/internal/httpapi/router_test.go
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
package httpapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRouterHealthz(t *testing.T) {
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
NewRouter().ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if got, want := w.Code, http.StatusOK; got != want {
|
||||||
|
t.Fatalf("status = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response struct {
|
||||||
|
Service string `json:"service"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||||
|
t.Fatalf("Unmarshal() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Service, "morz-infoboard-backend"; got != want {
|
||||||
|
t.Fatalf("service = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Status, "ok"; got != want {
|
||||||
|
t.Fatalf("status field = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRouterBaseAPI(t *testing.T) {
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
NewRouter().ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if got, want := w.Code, http.StatusOK; got != want {
|
||||||
|
t.Fatalf("status = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Tools []string `json:"tools"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||||
|
t.Fatalf("Unmarshal() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Name, "morz-infoboard-backend"; got != want {
|
||||||
|
t.Fatalf("name = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Version, "dev"; got != want {
|
||||||
|
t.Fatalf("version = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := len(response.Tools), 1; got != want {
|
||||||
|
t.Fatalf("len(tools) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Tools[0], "message-wall-resolve"; got != want {
|
||||||
|
t.Fatalf("tool[0] = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRouterMeta(t *testing.T) {
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/meta", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
NewRouter().ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if got, want := w.Code, http.StatusOK; got != want {
|
||||||
|
t.Fatalf("status = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response struct {
|
||||||
|
Service string `json:"service"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
API struct {
|
||||||
|
BasePath string `json:"base_path"`
|
||||||
|
Health string `json:"health"`
|
||||||
|
Tools []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
} `json:"tools"`
|
||||||
|
} `json:"api"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||||
|
t.Fatalf("Unmarshal() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.API.BasePath, "/api/v1"; got != want {
|
||||||
|
t.Fatalf("api.base_path = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.API.Health, "/healthz"; got != want {
|
||||||
|
t.Fatalf("api.health = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := len(response.API.Tools), 1; got != want {
|
||||||
|
t.Fatalf("len(api.tools) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.API.Tools[0].Path, "/api/v1/tools/message-wall/resolve"; got != want {
|
||||||
|
t.Fatalf("api.tools[0].path = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRouterPlayerStatusRoute(t *testing.T) {
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/player/status", bytes.NewBufferString(`{"screen_id":"demo","ts":"2026-03-22T16:00:00Z","status":"running"}`))
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
NewRouter().ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if got, want := w.Code, http.StatusOK; got != want {
|
||||||
|
t.Fatalf("status = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue