mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
a47179f142
by pinging the mysql and redis backends. For #93
45 lines
835 B
Go
45 lines
835 B
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHealthz(t *testing.T) {
|
|
failing := healthz(map[string]interface{}{
|
|
"mock": healthcheckFunc(func() error {
|
|
return errors.New("health check failed")
|
|
})})
|
|
ok := healthz(map[string]interface{}{
|
|
"mock": healthcheckFunc(func() error {
|
|
return nil
|
|
})})
|
|
|
|
var httpTests = []struct {
|
|
wantHeader int
|
|
handler http.Handler
|
|
}{
|
|
{200, ok},
|
|
{500, failing},
|
|
}
|
|
for _, tt := range httpTests {
|
|
t.Run("", func(t *testing.T) {
|
|
rr := httptest.NewRecorder()
|
|
req := httptest.NewRequest("GET", "/healthz", nil)
|
|
tt.handler.ServeHTTP(rr, req)
|
|
assert.Equal(t, rr.Code, tt.wantHeader)
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
type healthcheckFunc func() error
|
|
|
|
func (fn healthcheckFunc) HealthCheck() error {
|
|
return fn()
|
|
}
|