From e0ba15e77cfe922ece762f487269cb4e626ca290 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Thu, 12 Dec 2019 20:34:13 +1300 Subject: Watch a file to configure which domains should use new gitlab source Instead of passing domains once in an ENV variable we now watcn a config file (specified with `GITLAB_SOURCE_CONFIG_FILE`, defaults to `.gitlab-source-config.yml` and update ednabled/broken domains when it's content change. This way we can control this without having to restart Pages. Related to https://gitlab.com/gitlab-org/gitlab-pages/issues/266. --- acceptance_test.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'acceptance_test.go') diff --git a/acceptance_test.go b/acceptance_test.go index ae1bf2b6..49d391b1 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -432,20 +432,6 @@ func TestPageNotAvailableIfNotLoaded(t *testing.T) { require.Equal(t, http.StatusServiceUnavailable, rsp.StatusCode) } -func TestPageNotAvailableInDomainSource(t *testing.T) { - skipUnlessEnabled(t) - - brokenDomain := "GITLAB_NEW_SOURCE_BROKEN_DOMAIN=pages-broken-poc.gitlab.io" - teardown := RunPagesProcessWithEnvs(t, false, *pagesBinary, listeners, "", []string{brokenDomain}, "-pages-root=shared/invalid-pages") - defer teardown() - waitForRoundtrips(t, listeners, 5*time.Second) - - rsp, err := GetPageFromListener(t, httpListener, "pages-broken-poc.gitlab.io", "index.html") - require.NoError(t, err) - defer rsp.Body.Close() - require.Equal(t, http.StatusBadGateway, rsp.StatusCode) -} - func TestObscureMIMEType(t *testing.T) { skipUnlessEnabled(t) teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "") @@ -1534,10 +1520,22 @@ func TestGitlabDomainsSource(t *testing.T) { source := NewGitlabDomainsSourceStub(t) defer source.Close() - newSourceDomains := "GITLAB_NEW_SOURCE_DOMAINS=new-source-test.gitlab.io,non-existent-domain.gitlab.io" + gitlabSourceConfig := ` +domains: + enabled: + - new-source-test.gitlab.io + broken: pages-broken-poc.gitlab.io +` + gitlabSourceConfigFile, cleanupGitlabSourceConfigFile := CreateGitlabSourceConfigFixtureFile(t, gitlabSourceConfig) + defer cleanupGitlabSourceConfigFile() + + gitlabSourceConfigFile = "GITLAB_SOURCE_CONFIG_FILE=" + gitlabSourceConfigFile + gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) + pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey} - teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{newSourceDomains}, pagesArgs...) + + teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{gitlabSourceConfigFile}, pagesArgs...) defer teardown() t.Run("when a domain exists", func(t *testing.T) { @@ -1558,4 +1556,13 @@ func TestGitlabDomainsSource(t *testing.T) { require.Equal(t, http.StatusNotFound, response.StatusCode) }) + + t.Run("broken domain is requested", func(t *testing.T) { + response, err := GetPageFromListener(t, httpListener, "pages-broken-poc.gitlab.io", "index.html") + require.NoError(t, err) + + defer response.Body.Close() + + require.Equal(t, http.StatusBadGateway, response.StatusCode) + }) } -- cgit v1.2.3