34 lines
760 B
Go
34 lines
760 B
Go
package httpapi
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"drive.local/drivev2/internal/config"
|
|
)
|
|
|
|
func TestLiveHealth(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
server := NewServer(
|
|
config.Config{HTTPAddress: ":0", WebRoot: t.TempDir()},
|
|
"test",
|
|
slog.New(slog.NewTextHandler(io.Discard, nil)),
|
|
http.NotFoundHandler(),
|
|
)
|
|
request := httptest.NewRequest(http.MethodGet, "/health/live", nil)
|
|
recorder := httptest.NewRecorder()
|
|
|
|
server.httpServer.Handler.ServeHTTP(recorder, request)
|
|
|
|
if recorder.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want %d", recorder.Code, http.StatusOK)
|
|
}
|
|
if !strings.Contains(recorder.Body.String(), `"status":"live"`) {
|
|
t.Fatalf("unexpected body: %s", recorder.Body.String())
|
|
}
|
|
}
|