diff options
author | Vladimir Shushlin <vshushlin@gitlab.com> | 2020-08-04 11:54:44 +0300 |
---|---|---|
committer | Vladimir Shushlin <vshushlin@gitlab.com> | 2020-08-04 11:54:44 +0300 |
commit | e1ec61bf5ddc36c69512f0b619bce2392d9db2d2 (patch) | |
tree | ec67166ed68765b487f6bf17f9d463160eb22eb4 /helpers_test.go | |
parent | a3365a7b1b41b3dee206cbcf27e915ee45d556a5 (diff) |
Revert "Merge branch 'use-domain-config-source-disk' into 'master'"revert-a3365a7b
This reverts merge request !305
Diffstat (limited to 'helpers_test.go')
-rw-r--r-- | helpers_test.go | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/helpers_test.go b/helpers_test.go index a55399f4..32bea87c 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strings" "testing" "time" @@ -87,6 +88,27 @@ 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 { @@ -421,12 +443,7 @@ func waitForRoundtrips(t *testing.T, listeners []ListenSpec, timeout time.Durati } func NewGitlabDomainsSourceStub(t *testing.T) *httptest.Server { - 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) { + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { domain := r.URL.Query().Get("host") path := "shared/lookups/" + domain + ".json" @@ -445,10 +462,9 @@ 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(mux) + return httptest.NewServer(handler) } func newConfigFile(configs ...string) (string, error) { |