32 lines
742 B
Go
32 lines
742 B
Go
package health_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/veylant/ia-gateway/internal/health"
|
|
)
|
|
|
|
func TestHandler_Returns200WithJSONBody(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
|
rec := httptest.NewRecorder()
|
|
|
|
health.Handler(rec, req)
|
|
|
|
assert.Equal(t, http.StatusOK, rec.Code)
|
|
assert.Equal(t, "application/json", rec.Header().Get("Content-Type"))
|
|
|
|
var body struct {
|
|
Status string `json:"status"`
|
|
Timestamp string `json:"timestamp"`
|
|
}
|
|
require.NoError(t, json.NewDecoder(rec.Body).Decode(&body))
|
|
assert.Equal(t, "ok", body.Status)
|
|
assert.NotEmpty(t, body.Timestamp)
|
|
}
|