diff options
-rw-r--r-- | test/acceptance/helpers_test.go | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index 2aa7041d..11c0f381 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -273,10 +273,6 @@ func RunPagesProcessWithAuth(t *testing.T, pagesBinary string, listeners []Liste return cleanup2 } -func RunPagesProcessWithGitlabServer(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, gitlabServer string) func() { - return runPagesProcessWithGitlabServer(t, pagesBinary, listeners, promPort, nil, gitlabServer) -} - func RunPagesProcessWithGitlabServerWithSSLCertFile(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, sslCertFile string, gitlabServer string) func() { return runPagesProcessWithGitlabServer(t, pagesBinary, listeners, promPort, []string{"SSL_CERT_FILE=" + sslCertFile}, gitlabServer) @@ -581,6 +577,8 @@ type stubOpts struct { m sync.RWMutex apiCalled bool statusReadyCount int + authHandler http.HandlerFunc + userHandler http.HandlerFunc statusHandler http.HandlerFunc pagesHandler http.HandlerFunc pagesStatusResponse int @@ -616,6 +614,20 @@ func NewGitlabDomainsSourceStub(t *testing.T, opts *stubOpts) *httptest.Server { mux.HandleFunc("/api/v4/internal/pages", pagesHandler) + authHandler := defaultAuthHandler(t, opts) + if opts.authHandler != nil { + authHandler = opts.authHandler + } + + mux.HandleFunc("/oauth/token", authHandler) + + userHandler := defaultUserHandler(t, opts) + if opts.userHandler != nil { + userHandler = opts.userHandler + } + + mux.HandleFunc("/api/v4/user", userHandler) + return httptest.NewServer(mux) } @@ -679,6 +691,25 @@ func defaultAPIHandler(t *testing.T, opts *stubOpts) http.HandlerFunc { } } +func defaultAuthHandler(t *testing.T, opts *stubOpts) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, "POST", r.Method) + err := json.NewEncoder(w).Encode(struct { + AccessToken string `json:"access_token"` + }{ + AccessToken: "abc", + }) + require.NoError(t, err) + } +} + +func defaultUserHandler(t *testing.T, opts *stubOpts) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) + w.WriteHeader(http.StatusOK) + } +} + func newConfigFile(t *testing.T, configs ...string) string { t.Helper() |