Files
director-app/api/handlers/version_test.go
director-agent 48b1fa18f6 plan/11: Add GET /api/version endpoint
Adds handlers/version.go returning hardcoded {"version":"0.1.0","name":"director","commit":"unknown"},
wires GET /api/version into main.go next to /api/health, and adds
handlers/version_test.go using httptest (no DB dependency).

Co-Authored-By: director-agent <director-agent@dragonchain.com>
2026-04-08 10:59:37 -05:00

36 lines
709 B
Go

package handlers
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestGetVersion(t *testing.T) {
gin.SetMode(gin.TestMode)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/api/version", nil)
h := &Handler{db: nil, ps: nil}
h.GetVersion(c)
if w.Code != http.StatusOK {
t.Errorf("expected 200, got %d", w.Code)
}
var body map[string]any
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
t.Fatalf("invalid json: %v", err)
}
for _, field := range []string{"version", "name", "commit"} {
if _, ok := body[field]; !ok {
t.Errorf("missing field: %s", field)
}
}
}