22 lines
649 B
Go
22 lines
649 B
Go
package httpserver
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHealthSeparatesLivenessAndReadiness(t *testing.T) {
|
|
server := New("127.0.0.1:0", func(context.Context) error { return errors.New("internal-database-details") })
|
|
for path, want := range map[string]int{"/health/live": 200, "/health/ready": 503, "/v1/tasks": 404} {
|
|
rr := httptest.NewRecorder()
|
|
server.Handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, path, nil))
|
|
if rr.Code != want || strings.Contains(rr.Body.String(), "internal-database-details") {
|
|
t.Fatalf("%s: %d %s", path, rr.Code, rr.Body.String())
|
|
}
|
|
}
|
|
}
|