diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-06-15 10:38:24 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-06-23 02:22:26 +0300 |
commit | 4056bf44a8c8274d817e7e8f86452c0189e55592 (patch) | |
tree | b9bce494eef9c0eca8acaafbdb261bab748299c5 /test/acceptance | |
parent | afeb8a4cdc17289b83f5e7d77aebb9a0e62e2f58 (diff) |
Use stub in artifacts_test.go
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/artifacts_test.go | 38 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go | 5 | ||||
-rw-r--r-- | test/acceptance/stub_test.go | 16 |
3 files changed, 33 insertions, 26 deletions
diff --git a/test/acceptance/artifacts_test.go b/test/acceptance/artifacts_test.go index b4dcdce4..476c67c1 100644 --- a/test/acceptance/artifacts_test.go +++ b/test/acceptance/artifacts_test.go @@ -131,16 +131,16 @@ func TestArtifactProxyRequest(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - teardown := RunPagesProcessWithSSLCertFile( - t, - *pagesBinary, - supportedListeners(), - "", - certFile, - "-artifacts-server="+artifactServerURL, - tt.binaryOption, + args := []string{"-artifacts-server=" + artifactServerURL} + if tt.binaryOption != "" { + args = append(args, tt.binaryOption) + } + + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpListener}), + withArguments(args), + withEnv([]string{"SSL_CERT_FILE=" + certFile}), ) - defer teardown() resp, err := GetPageFromListener(t, httpListener, tt.host, tt.path) require.NoError(t, err) @@ -170,8 +170,10 @@ func TestPrivateArtifactProxyRequest(t *testing.T) { keyFile, certFile := CreateHTTPSFixtureFiles(t) cert, err := tls.LoadX509KeyPair(certFile, keyFile) require.NoError(t, err) - defer os.Remove(keyFile) - defer os.Remove(certFile) + t.Cleanup(func() { + os.Remove(keyFile) + os.Remove(certFile) + }) testServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} testServer.StartTLS() @@ -235,15 +237,13 @@ func TestPrivateArtifactProxyRequest(t *testing.T) { tt.binaryOption) defer cleanup() - teardown := RunPagesProcessWithSSLCertFile( - t, - *pagesBinary, - supportedListeners(), - "", - certFile, - "-config="+configFile, + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpsListener}), + withArguments([]string{ + "-config=" + configFile, + }), + withEnv([]string{"SSL_CERT_FILE=" + certFile}), ) - defer teardown() resp, err := GetRedirectPage(t, httpsListener, tt.host, tt.path) require.NoError(t, err) diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index 2b95cf4b..b267f1a2 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -216,11 +216,6 @@ func RunPagesProcessWithoutWait(t *testing.T, pagesBinary string, listeners []Li return cleanup } -func RunPagesProcessWithSSLCertFile(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, sslCertFile string, extraArgs ...string) (teardown func()) { - _, cleanup := runPagesProcess(t, true, pagesBinary, listeners, promPort, []string{"SSL_CERT_FILE=" + sslCertFile}, extraArgs...) - return cleanup -} - func RunPagesProcessWithEnvs(t *testing.T, wait bool, pagesBinary string, listeners []ListenSpec, promPort string, envs []string, extraArgs ...string) (teardown func()) { _, cleanup := runPagesProcess(t, wait, pagesBinary, listeners, promPort, envs, extraArgs...) return cleanup diff --git a/test/acceptance/stub_test.go b/test/acceptance/stub_test.go index 3fcb179d..6346fe4e 100644 --- a/test/acceptance/stub_test.go +++ b/test/acceptance/stub_test.go @@ -69,8 +69,15 @@ func withArguments(args []string) processOption { func makeGitLabPagesAccessStub(t *testing.T) *httptest.Server { t.Helper() - return httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + return httptest.NewUnstartedServer(apiHandler(t)) +} + +func apiHandler(t *testing.T) http.HandlerFunc { + t.Helper() + + return func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { + // TODO: move OAuth and user endpoints to NewGitlabDomainsSourceStub case "/oauth/token": require.Equal(t, "POST", r.Method) w.WriteHeader(http.StatusOK) @@ -78,13 +85,18 @@ func makeGitLabPagesAccessStub(t *testing.T) *httptest.Server { case "/api/v4/user": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) + case "/api/v4/internal/pages/status": + // Temporarily adding these handlers to this stub. + w.WriteHeader(http.StatusNoContent) + case "/api/v4/internal/pages": + defaultAPIHandler(t, &stubOpts{})(w, r) default: if handleAccessControlArtifactRequests(t, w, r) { return } handleAccessControlRequests(t, w, r) } - })) + } } func CreateHTTPSFixtureFiles(t *testing.T) (key string, cert string) { |