Add tests for health route
This commit is contained in:
@ -23,4 +23,4 @@ test:
|
|||||||
stage: test
|
stage: test
|
||||||
needs: []
|
needs: []
|
||||||
script:
|
script:
|
||||||
- go test -v
|
- go test ./... -v
|
||||||
|
23
api/health_test.go
Normal file
23
api/health_test.go
Normal 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)
|
||||||
|
}
|
Reference in New Issue
Block a user