fix: use backend for /healthz page (#4938)

This commit is contained in:
Colin Adler
2022-11-07 13:35:52 -06:00
committed by GitHub
parent bda76368bc
commit 50ad4a8535
7 changed files with 18 additions and 36 deletions

View File

@ -233,6 +233,8 @@ func New(options *Options) *API {
httpmw.CSRF(options.SecureAuthCookie),
)
r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) })
apps := func(r chi.Router) {
r.Use(
tracing.Middleware(api.TracerProvider),

View File

@ -2,6 +2,7 @@ package coderd_test
import (
"context"
"io"
"net/http"
"net/netip"
"strconv"
@ -114,3 +115,17 @@ func TestDERPLatencyCheck(t *testing.T) {
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
}
func TestHealthz(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
res, err := client.Request(context.Background(), http.MethodGet, "/healthz", nil)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
body, err := io.ReadAll(res.Body)
require.NoError(t, err)
assert.Equal(t, "OK", string(body))
}

View File

@ -37,6 +37,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
assertRoute := map[string]RouteCheck{
// These endpoints do not require auth
"GET:/healthz": {NoAuthorize: true},
"GET:/api/v2": {NoAuthorize: true},
"GET:/api/v2/buildinfo": {NoAuthorize: true},
"GET:/api/v2/users/first": {NoAuthorize: true},