Add tests for health route

This commit is contained in:
Felix Auringer
2021-04-26 12:30:26 +02:00
parent f8e864efdd
commit 38434cef27
2 changed files with 24 additions and 1 deletions

View File

@ -23,4 +23,4 @@ test:
stage: test
needs: []
script:
- go test -v
- go test ./... -v

23
api/health_test.go Normal file
View File

@ -0,0 +1,23 @@
package api
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthRoute(t *testing.T) {
req, err := http.NewRequest("GET", "/health", nil)
if err != nil {
t.Fatal(err)
}
rec := httptest.NewRecorder()
http.HandlerFunc(Health).ServeHTTP(rec, req)
res := &Message{}
_ = json.NewDecoder(rec.Body).Decode(res)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "I'm alive!", res.Msg)
}