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) } } }