diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-07-28 07:40:19 +0300 |
---|---|---|
committer | Vladimir Shushlin <v.shushlin@gmail.com> | 2020-08-04 11:23:51 +0300 |
commit | ee43b1ab04e8aa2e17546035ea2901096dc0b823 (patch) | |
tree | b2a02fb2f008d52cf8817b5d4c833838985ca47b | |
parent | 7c9cc5a4f19f1f160f49f0a8f227cfa7af8be181 (diff) |
Update acceptance tests without gitlabsourceconfig
-rw-r--r-- | acceptance_test.go | 27 | ||||
-rw-r--r-- | helpers_test.go | 34 | ||||
-rw-r--r-- | main.go | 1 |
3 files changed, 14 insertions, 48 deletions
diff --git a/acceptance_test.go b/acceptance_test.go index acceaa8e..abcf3592 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -1714,22 +1714,11 @@ func TestGitlabDomainsSource(t *testing.T) { source := NewGitlabDomainsSourceStub(t) defer source.Close() - 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, "-domain-config-source", ""} + pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, "-domain-config-source", "gitlab"} - teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{gitlabSourceConfigFile}, pagesArgs...) + teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, listeners, "", []string{}, pagesArgs...) defer teardown() t.Run("when a domain exists", func(t *testing.T) { @@ -1737,7 +1726,8 @@ domains: require.NoError(t, err) defer response.Body.Close() - body, _ := ioutil.ReadAll(response.Body) + body, err := ioutil.ReadAll(response.Body) + require.NoError(t, err) require.Equal(t, http.StatusOK, response.StatusCode) require.Equal(t, "New Pages GitLab Source TEST OK\n", string(body)) @@ -1750,13 +1740,4 @@ domains: 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) - }) } diff --git a/helpers_test.go b/helpers_test.go index 32bea87c..a55399f4 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -13,7 +13,6 @@ import ( "os" "os/exec" "path" - "path/filepath" "strings" "testing" "time" @@ -88,27 +87,6 @@ func CreateGitLabAPISecretKeyFixtureFile(t *testing.T) (filepath string) { return secretfile.Name() } -func CreateGitlabSourceConfigFixtureFile(t *testing.T, domains string) (filename string, cleanup func()) { - configfile, err := ioutil.TempFile("shared/pages", "gitlab-source-config-*") - require.NoError(t, err) - configfile.Close() - - cleanup = func() { - os.RemoveAll(configfile.Name()) - } - - require.NoError(t, ioutil.WriteFile(configfile.Name(), []byte(domains), 0644)) - - filename, err = filepath.Abs(configfile.Name()) - require.NoError(t, err) - - if os.Getenv("TEST_DAEMONIZE") != "" { - filename = filepath.Base(filename) - } - - return filename, cleanup -} - // ListenSpec is used to point at a gitlab-pages http server, preserving the // type of port it is (http, https, proxy) type ListenSpec struct { @@ -443,7 +421,12 @@ func waitForRoundtrips(t *testing.T, listeners []ListenSpec, timeout time.Durati } func NewGitlabDomainsSourceStub(t *testing.T) *httptest.Server { - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mux := http.NewServeMux() + mux.HandleFunc("/api/v4/internal/pages/status", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNoContent) + }) + + handler := func(w http.ResponseWriter, r *http.Request) { domain := r.URL.Query().Get("host") path := "shared/lookups/" + domain + ".json" @@ -462,9 +445,10 @@ func NewGitlabDomainsSourceStub(t *testing.T) *httptest.Server { require.NoError(t, err) t.Logf("GitLab domain %s source stub served lookup", domain) - }) + } + mux.HandleFunc("/api/v4/internal/pages", handler) - return httptest.NewServer(handler) + return httptest.NewServer(mux) } func newConfigFile(configs ...string) (string, error) { @@ -289,6 +289,7 @@ func loadConfig() appConfig { "gitlab-server": config.GitLabServer, "internal-gitlab-server": config.InternalGitLabServer, "api-secret-key": *gitLabAPISecretKey, + "domain-config-source": config.DomainConfigurationSource, "auth-redirect-uri": config.RedirectURI, }).Debug("Start daemon with configuration") |