diff options
-rw-r--r-- | Makefile.util.mk | 2 | ||||
-rw-r--r-- | test/acceptance/acceptance_test.go (renamed from acceptance_test.go) | 14 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go (renamed from helpers_test.go) | 66 |
3 files changed, 49 insertions, 33 deletions
diff --git a/Makefile.util.mk b/Makefile.util.mk index ea465fbf..8c8a5c93 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -16,7 +16,7 @@ race: .GOPATH/.ok gitlab-pages CGO_ENABLED=1 go test -race $(if $V,-v) $(allpackages) acceptance: .GOPATH/.ok gitlab-pages - go test $(if $V,-v) $(IMPORT_PATH) + go test $(if $V,-v) ./test/acceptance -tags acceptance bench: .GOPATH/.ok gitlab-pages go test -bench=. -run=^$$ $(allpackages) diff --git a/acceptance_test.go b/test/acceptance/acceptance_test.go index a6ac31d0..35815fc1 100644 --- a/acceptance_test.go +++ b/test/acceptance/acceptance_test.go @@ -1,4 +1,6 @@ -package main +// +build acceptance + +package acceptance_test import ( "crypto/tls" @@ -19,7 +21,7 @@ import ( "github.com/stretchr/testify/require" ) -var pagesBinary = flag.String("gitlab-pages-binary", "./gitlab-pages", "Path to the gitlab-pages binary") +var pagesBinary = flag.String("gitlab-pages-binary", "../../gitlab-pages", "Path to the gitlab-pages binary") const ( objectStorageMockServer = "127.0.0.1:37003" @@ -452,7 +454,7 @@ func TestHttpsOnlyDomainDisabled(t *testing.T) { func TestPrometheusMetricsCanBeScraped(t *testing.T) { skipUnlessEnabled(t) - _, cleanup := newZipFileServerURL(t, "shared/pages/group/zip.gitlab.io/public.zip") + _, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip") defer cleanup() teardown := RunPagesProcessWithStubGitLabServer(t, true, *pagesBinary, listeners, ":42345", []string{}) @@ -621,7 +623,7 @@ func TestStatusPage(t *testing.T) { func TestStatusNotYetReady(t *testing.T) { skipUnlessEnabled(t) - teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "", "-pages-status=/@statuscheck", "-pages-root=shared/invalid-pages") + teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "", "-pages-status=/@statuscheck", "-pages-root=../../shared/invalid-pages") defer teardown() waitForRoundtrips(t, listeners, 5*time.Second) @@ -633,7 +635,7 @@ func TestStatusNotYetReady(t *testing.T) { func TestPageNotAvailableIfNotLoaded(t *testing.T) { skipUnlessEnabled(t) - teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "", "-pages-root=shared/invalid-pages") + teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "", "-pages-root=../../shared/invalid-pages") defer teardown() waitForRoundtrips(t, listeners, 5*time.Second) @@ -2019,7 +2021,7 @@ func TestZipServing(t *testing.T) { teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{}, pagesArgs...) defer teardown() - _, cleanup := newZipFileServerURL(t, "shared/pages/group/zip.gitlab.io/public.zip") + _, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip") defer cleanup() tests := map[string]struct { diff --git a/helpers_test.go b/test/acceptance/helpers_test.go index 2e6fec58..6cd0f812 100644 --- a/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -1,4 +1,6 @@ -package main +// +build acceptance + +package acceptance_test import ( "bytes" @@ -147,30 +149,30 @@ func (l ListenSpec) JoinHostPort() string { // GetPageFromProcess to do a HTTP GET against a listener. // // If run as root via sudo, the gitlab-pages process will drop privileges -func RunPagesProcess(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, extraArgs ...string) (teardown func()) { - return runPagesProcess(t, true, pagesPath, listeners, promPort, nil, extraArgs...) +func RunPagesProcess(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, extraArgs ...string) (teardown func()) { + return runPagesProcess(t, true, pagesBinary, listeners, promPort, nil, extraArgs...) } -func RunPagesProcessWithoutWait(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, extraArgs ...string) (teardown func()) { - return runPagesProcess(t, false, pagesPath, listeners, promPort, nil, extraArgs...) +func RunPagesProcessWithoutWait(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, extraArgs ...string) (teardown func()) { + return runPagesProcess(t, false, pagesBinary, listeners, promPort, nil, extraArgs...) } -func RunPagesProcessWithSSLCertFile(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, sslCertFile string, extraArgs ...string) (teardown func()) { - return runPagesProcess(t, true, pagesPath, listeners, promPort, []string{"SSL_CERT_FILE=" + sslCertFile}, extraArgs...) +func RunPagesProcessWithSSLCertFile(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, sslCertFile string, extraArgs ...string) (teardown func()) { + return runPagesProcess(t, true, pagesBinary, listeners, promPort, []string{"SSL_CERT_FILE=" + sslCertFile}, extraArgs...) } -func RunPagesProcessWithEnvs(t *testing.T, wait bool, pagesPath string, listeners []ListenSpec, promPort string, envs []string, extraArgs ...string) (teardown func()) { - return runPagesProcess(t, wait, pagesPath, listeners, promPort, envs, extraArgs...) +func RunPagesProcessWithEnvs(t *testing.T, wait bool, pagesBinary string, listeners []ListenSpec, promPort string, envs []string, extraArgs ...string) (teardown func()) { + return runPagesProcess(t, wait, pagesBinary, listeners, promPort, envs, extraArgs...) } -func RunPagesProcessWithStubGitLabServer(t *testing.T, wait bool, pagesPath string, listeners []ListenSpec, promPort string, envs []string, extraArgs ...string) (teardown func()) { +func RunPagesProcessWithStubGitLabServer(t *testing.T, wait bool, pagesBinary string, listeners []ListenSpec, promPort string, envs []string, extraArgs ...string) (teardown func()) { var apiCalled bool source := NewGitlabDomainsSourceStub(t, &apiCalled) gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) pagesArgs := append([]string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, "-domain-config-source", "gitlab"}, extraArgs...) - cleanup := runPagesProcess(t, wait, pagesPath, listeners, promPort, envs, pagesArgs...) + cleanup := runPagesProcess(t, wait, pagesBinary, listeners, promPort, envs, pagesArgs...) return func() { source.Close() @@ -178,27 +180,27 @@ func RunPagesProcessWithStubGitLabServer(t *testing.T, wait bool, pagesPath stri } } -func RunPagesProcessWithAuth(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string) func() { +func RunPagesProcessWithAuth(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string) func() { configFile, cleanup := defaultConfigFileWith(t, "auth-server=https://gitlab-auth.com", "auth-redirect-uri=https://projects.gitlab-example.com/auth") defer cleanup() - return runPagesProcess(t, true, pagesPath, listeners, promPort, nil, + return runPagesProcess(t, true, pagesBinary, listeners, promPort, nil, "-config="+configFile, ) } -func RunPagesProcessWithAuthServer(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, authServer string) func() { - return runPagesProcessWithAuthServer(t, pagesPath, listeners, promPort, nil, authServer) +func RunPagesProcessWithAuthServer(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, authServer string) func() { + return runPagesProcessWithAuthServer(t, pagesBinary, listeners, promPort, nil, authServer) } -func RunPagesProcessWithAuthServerWithSSLCertFile(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, sslCertFile string, authServer string) func() { - return runPagesProcessWithAuthServer(t, pagesPath, listeners, promPort, +func RunPagesProcessWithAuthServerWithSSLCertFile(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, sslCertFile string, authServer string) func() { + return runPagesProcessWithAuthServer(t, pagesBinary, listeners, promPort, []string{"SSL_CERT_FILE=" + sslCertFile}, authServer) } -func RunPagesProcessWithAuthServerWithSSLCertDir(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, sslCertFile string, authServer string) func() { +func RunPagesProcessWithAuthServerWithSSLCertDir(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, sslCertFile string, authServer string) func() { // Create temporary cert dir sslCertDir, err := ioutil.TempDir("", "pages-test-SSL_CERT_DIR") require.NoError(t, err) @@ -207,7 +209,7 @@ func RunPagesProcessWithAuthServerWithSSLCertDir(t *testing.T, pagesPath string, err = copyFile(sslCertDir+"/"+path.Base(sslCertFile), sslCertFile) require.NoError(t, err) - innerCleanup := runPagesProcessWithAuthServer(t, pagesPath, listeners, promPort, + innerCleanup := runPagesProcessWithAuthServer(t, pagesBinary, listeners, promPort, []string{"SSL_CERT_DIR=" + sslCertDir}, authServer) return func() { @@ -216,29 +218,29 @@ func RunPagesProcessWithAuthServerWithSSLCertDir(t *testing.T, pagesPath string, } } -func runPagesProcessWithAuthServer(t *testing.T, pagesPath string, listeners []ListenSpec, promPort string, extraEnv []string, authServer string) func() { +func runPagesProcessWithAuthServer(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string, extraEnv []string, authServer string) func() { configFile, cleanup := defaultConfigFileWith(t, "auth-server="+authServer, "auth-redirect-uri=https://projects.gitlab-example.com/auth") defer cleanup() - return runPagesProcess(t, true, pagesPath, listeners, promPort, extraEnv, + return runPagesProcess(t, true, pagesBinary, listeners, promPort, extraEnv, "-config="+configFile) } -func runPagesProcess(t *testing.T, wait bool, pagesPath string, listeners []ListenSpec, promPort string, extraEnv []string, extraArgs ...string) (teardown func()) { +func runPagesProcess(t *testing.T, wait bool, pagesBinary string, listeners []ListenSpec, promPort string, extraEnv []string, extraArgs ...string) (teardown func()) { t.Helper() - _, err := os.Stat(pagesPath) + _, err := os.Stat(pagesBinary) require.NoError(t, err) args, tempfiles := getPagesArgs(t, listeners, promPort, extraArgs) - cmd := exec.Command(pagesPath, args...) + cmd := exec.Command(pagesBinary, args...) cmd.Env = append(os.Environ(), extraEnv...) cmd.Stdout = &tWriter{t} cmd.Stderr = &tWriter{t} require.NoError(t, cmd.Start()) - t.Logf("Running %s %v", pagesPath, args) + t.Logf("Running %s %v", pagesBinary, args) waitCh := make(chan struct{}) go func() { @@ -285,6 +287,10 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr args = append(args, "-root-key", key, "-root-cert", cert) } + if !contains(args, "pages-root") { + args = append(args, "-pages-root", "../../shared/pages") + } + if promPort != "" { args = append(args, "-metrics-address", promPort) } @@ -295,6 +301,14 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr return } +func contains(slice []string, s string) bool { + for _, e := range slice { + if e == s { + return true + } + } + return false +} func getPagesDaemonArgs(t *testing.T) []string { mode := os.Getenv("TEST_DAEMONIZE") if mode == "" { @@ -457,7 +471,7 @@ func NewGitlabDomainsSourceStub(t *testing.T, apiCalled *bool) *httptest.Server handler := func(w http.ResponseWriter, r *http.Request) { *apiCalled = true domain := r.URL.Query().Get("host") - path := "shared/lookups/" + domain + ".json" + path := "../../shared/lookups/" + domain + ".json" fixture, err := os.Open(path) if os.IsNotExist(err) { |