From 01bc799b99fcc5e60292293dfcafda8013cf60ff Mon Sep 17 00:00:00 2001 From: feistel <6742251-feistel@users.noreply.gitlab.com> Date: Mon, 7 Mar 2022 19:29:05 +0100 Subject: Move healthcheck middleware to a separate package add Cache-Control: no-store to status response --- app_test.go | 65 ------------------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'app_test.go') diff --git a/app_test.go b/app_test.go index 3b1d6697..75747a2d 100644 --- a/app_test.go +++ b/app_test.go @@ -3,18 +3,14 @@ package main import ( "crypto/tls" "fmt" - "io" "net/http" "net/http/httptest" "testing" - "time" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitlab-pages/internal/config" "gitlab.com/gitlab-org/gitlab-pages/internal/request" - "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab" "gitlab.com/gitlab-org/gitlab-pages/metrics" ) @@ -66,67 +62,6 @@ func newGetRequestWithScheme(t *testing.T, scheme string, withTLS bool) *http.Re return req } -func TestHealthCheckMiddleware(t *testing.T) { - tests := []struct { - name string - path string - status int - body string - }{ - { - name: "Not a healthcheck request", - path: "/foo/bar", - status: http.StatusOK, - body: "Hello from inner handler", - }, - { - name: "Healthcheck request", - path: "/-/healthcheck", - status: http.StatusOK, - body: "success\n", - }, - } - - validCfg := config.GitLab{ - InternalServer: "server", - APISecretKey: []byte("secret"), - ClientHTTPTimeout: time.Second, - JWTTokenExpiration: time.Second, - } - - source, err := gitlab.New(&validCfg) - require.NoError(t, err) - - cfg := config.Config{ - General: config.General{ - StatusPath: "/-/healthcheck", - }, - } - - app := theApp{ - config: &cfg, - source: source, - } - - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - io.WriteString(w, "Hello from inner handler") - }) - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - r := httptest.NewRequest("GET", tc.path, nil) - rr := httptest.NewRecorder() - - middleware := app.healthCheckMiddleware(handler) - middleware.ServeHTTP(rr, r) - - require.Equal(t, tc.status, rr.Code) - require.Equal(t, tc.body, rr.Body.String()) - }) - } -} - func TestHandlePanicMiddleware(t *testing.T) { next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { panic("on purpose") -- cgit v1.2.3