diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-03-07 21:29:05 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-04-20 17:38:08 +0300 |
commit | 01bc799b99fcc5e60292293dfcafda8013cf60ff (patch) | |
tree | b7b4cfb59834716534eb2724271a9e69d9fdb166 /app_test.go | |
parent | dabfd71101d4598f31ab474f6a7bfc75bfa0a045 (diff) |
Move healthcheck middleware to a separate package
add Cache-Control: no-store to status response
Diffstat (limited to 'app_test.go')
-rw-r--r-- | app_test.go | 65 |
1 files changed, 0 insertions, 65 deletions
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") |