test version

master
breel 2020-08-08 21:36:55 -06:00
parent a406287127
commit ac7833338c
1 changed files with 30 additions and 0 deletions

30
server/version_test.go Normal file
View File

@ -0,0 +1,30 @@
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()))
}
}