mirror of
https://github.com/restic/rest-server.git
synced 2026-10-15 15:10:07 -07:00
Add /healthz endpoint to server (#259)
Co-authored-by: Michael Eischer <michael.eischer@fau.de>
This commit is contained in:
co-authored by
Michael Eischer
parent
a0da64d6cc
commit
652b604c90
@@ -112,6 +112,9 @@ func NewHandler(server *Server) (http.Handler, error) {
|
||||
mux.HandleFunc("/metrics", server.wrapMetricsAuth(promhttp.Handler().ServeHTTP))
|
||||
}
|
||||
}
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
mux.Handle("/", server)
|
||||
|
||||
var handler http.Handler = mux
|
||||
|
||||
+16
@@ -80,6 +80,22 @@ func TestCheckAuth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthz(t *testing.T) {
|
||||
handler, err := NewHandler(&Server{NoAuth: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/healthz", nil))
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNoContent)
|
||||
}
|
||||
if rec.Body.Len() != 0 {
|
||||
t.Fatalf("body = %q, want empty", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnauthorizedResponsesIncludeBasicChallenge(t *testing.T) {
|
||||
const challenge = `Basic realm="rest-server"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user