package server import ( "encoding/json" "net/http" "net/http/httptest" "testing" "github.com/google/uuid" ) func TestVersion(t *testing.T) { rest := &REST{} w := httptest.NewRecorder() s := uuid.New().String() GitCommit = s rest.version(w, nil) if w.Code != http.StatusOK { t.Fatal(w.Code) } var resp struct { Version string `json:"version"` } if err := json.NewDecoder(w.Body).Decode(&resp); err != nil { t.Fatal(err) } if resp.Version != s { t.Fatal(string(w.Body.Bytes())) } }