diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2022-01-25 10:55:59 +0300 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2022-01-25 10:55:59 +0300 |
commit | 58a67cf0f0152a87b4944c92c701be602ac33c2e (patch) | |
tree | a0b64f77668d6bd1e25baeb175907aab5dbf9f11 /test/acceptance/helpers_test.go | |
parent | ba74fa849ecc80683438165bffbbbf415a143587 (diff) | |
parent | 7344f49b62b9e1af88b936dda02997ce00d0d8dd (diff) |
Merge branch 'cleanup/gitlab-server-stub' into 'master'
test: cleanup gitlab server stub and stubOpts
See merge request gitlab-org/gitlab-pages!652
Diffstat (limited to 'test/acceptance/helpers_test.go')
-rw-r--r-- | test/acceptance/helpers_test.go | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index d21df0a8..b9cba467 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -220,7 +220,8 @@ func RunPagesProcess(t *testing.T, opts ...processOption) *LogCaptureBuffer { processCfg.gitlabStubOpts.pagesRoot = wd } - source := NewGitlabDomainsSourceStub(t, processCfg.gitlabStubOpts) + source := NewGitlabUnstartedServerStub(t, processCfg.gitlabStubOpts) + source.Start() gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) processCfg.extraArgs = append( @@ -443,17 +444,14 @@ func ClientWithConfig(tlsConfig *tls.Config) (*http.Client, func()) { } type stubOpts struct { - m sync.RWMutex - apiCalled bool - authHandler http.HandlerFunc - userHandler http.HandlerFunc - pagesHandler http.HandlerFunc - pagesStatusResponse int - pagesRoot string - delay time.Duration + m sync.RWMutex + apiCalled bool + pagesHandler http.HandlerFunc + pagesRoot string + delay time.Duration } -func NewGitlabDomainsSourceStub(t *testing.T, opts *stubOpts) *httptest.Server { +func NewGitlabUnstartedServerStub(t *testing.T, opts *stubOpts) *httptest.Server { t.Helper() require.NotNil(t, opts) @@ -467,28 +465,21 @@ func NewGitlabDomainsSourceStub(t *testing.T, opts *stubOpts) *httptest.Server { router.HandleFunc("/api/v4/internal/pages", pagesHandler) authHandler := defaultAuthHandler(t) - if opts.authHandler != nil { - authHandler = opts.authHandler - } - router.HandleFunc("/oauth/token", authHandler) userHandler := defaultUserHandler(t) - if opts.userHandler != nil { - userHandler = opts.userHandler - } - router.HandleFunc("/api/v4/user", userHandler) router.HandleFunc("/api/v4/projects/{project_id:[0-9]+}/pages_access", func(w http.ResponseWriter, r *http.Request) { - if handleAccessControlArtifactRequests(t, w, r) { - return - } - handleAccessControlRequests(t, w, r) }) - return httptest.NewServer(router) + router.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ok := handleAccessControlArtifactRequests(t, w, r) + require.True(t, ok) + }) + + return httptest.NewUnstartedServer(router) } func (o *stubOpts) setAPICalled(v bool) { @@ -538,11 +529,6 @@ func defaultAPIHandler(t *testing.T, opts *stubOpts) http.HandlerFunc { opts.setAPICalled(true) - if opts.pagesStatusResponse != 0 { - w.WriteHeader(opts.pagesStatusResponse) - return - } - // check if predefined response exists if responseFn, ok := testdata.DomainResponses[domain]; ok { err := json.NewEncoder(w).Encode(responseFn(t, opts.pagesRoot)) |