Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
32 lines
701 B
Go
32 lines
701 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func TestHeartbeat(t *testing.T) {
|
|
endpoint := "/ping"
|
|
|
|
r := chi.NewRouter()
|
|
r.Use(Heartbeat(endpoint))
|
|
r.Handle(endpoint, http.NotFoundHandler())
|
|
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodGet, endpoint, http.NoBody)
|
|
r.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("heartbeat: unexpected response code: %v", w.Code)
|
|
}
|
|
if w.Body.String() != "." {
|
|
t.Errorf("heartbeat: unexpected response body: %q", w.Body.String())
|
|
}
|
|
if got := w.Header().Get("Content-Type"); got != "text/plain" {
|
|
t.Errorf("heartbeat: unexpected Content-Type: %q", got)
|
|
}
|
|
}
|