Files
poseidon/api/health_test.go
Felix Auringer 712d0e6420 Cleanup code
This changes variable names that were abbreviations, uses more constants
from the net/http package and improves the json decoding / encoding.
2021-04-27 08:57:31 +02:00

24 lines
522 B
Go

package api
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthRoute(t *testing.T) {
request, err := http.NewRequest(http.MethodGet, "/health", nil)
if err != nil {
t.Fatal(err)
}
recorder := httptest.NewRecorder()
http.HandlerFunc(Health).ServeHTTP(recorder, request)
result := Message{}
_ = json.Unmarshal(recorder.Body.Bytes(), &result)
assert.Equal(t, http.StatusOK, recorder.Code)
assert.Equal(t, "I'm alive!", result.Message)
}