diff options
-rw-r--r-- | app_test.go | 2 | ||||
-rw-r--r-- | internal/source/domains.go | 4 | ||||
-rw-r--r-- | internal/source/domains_test.go | 120 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go | 11 | ||||
-rw-r--r-- | test/acceptance/serving_test.go | 49 |
5 files changed, 8 insertions, 178 deletions
diff --git a/app_test.go b/app_test.go index 48a6013b..a141663e 100644 --- a/app_test.go +++ b/app_test.go @@ -88,7 +88,7 @@ func TestHealthCheckMiddleware(t *testing.T) { require.NoError(t, err) cfg.General.StatusPath = "/-/healthcheck" - domains, err := source.NewDomains("auto", &cfg.GitLab) + domains, err := source.NewDomains(&cfg.GitLab) require.NoError(t, err) app := theApp{ diff --git a/internal/source/domains.go b/internal/source/domains.go index b437c6ef..9dc5a74b 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -8,9 +8,9 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab" ) -// Domains struct represents a map of all domains supported by pages. +// Domains struct represents a map of all domains supported by pages. type Domains struct { - gitlab Source + gitlab Source } // NewDomains is a factory method for domains initializing a mutex. It should diff --git a/internal/source/domains_test.go b/internal/source/domains_test.go index 8618df38..10923be3 100644 --- a/internal/source/domains_test.go +++ b/internal/source/domains_test.go @@ -3,105 +3,12 @@ package source import ( "context" "testing" - "time" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitlab-pages/internal/config" "gitlab.com/gitlab-org/gitlab-pages/internal/domain" - "gitlab.com/gitlab-org/gitlab-pages/internal/source/disk" ) -func TestNewDomains(t *testing.T) { - validCfg := config.GitLab{ - InternalServer: "https://gitlab.com", - APISecretKey: []byte("abc"), - ClientHTTPTimeout: time.Second, - JWTTokenExpiration: time.Second, - } - - tests := []struct { - name string - source string - config config.GitLab - expectedErr string - expectGitlabNil bool - expectDiskNil bool - }{ - { - name: "no_source_config", - source: "", - expectedErr: "invalid option for -domain-config-source: \"\"", - }, - { - name: "invalid_source_config", - source: "invalid", - expectedErr: "invalid option for -domain-config-source: \"invalid\"", - }, - { - name: "disk_source", - source: "disk", - expectGitlabNil: true, - expectDiskNil: false, - }, - { - name: "auto_without_api_config", - source: "auto", - expectGitlabNil: true, - expectDiskNil: false, - }, - { - name: "auto_with_api_config", - source: "auto", - config: validCfg, - expectGitlabNil: false, - expectDiskNil: false, - }, - { - name: "gitlab_source_success", - source: "gitlab", - config: validCfg, - expectDiskNil: true, - }, - { - name: "gitlab_source_no_url", - source: "gitlab", - config: func() config.GitLab { - cfg := validCfg - cfg.InternalServer = "" - - return cfg - }(), - expectedErr: "GitLab API URL or API secret has not been provided", - }, - { - name: "gitlab_source_no_secret", - source: "gitlab", - config: func() config.GitLab { - cfg := validCfg - cfg.APISecretKey = []byte{} - - return cfg - }(), - expectedErr: "GitLab API URL or API secret has not been provided", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - domains, err := NewDomains(tt.source, &tt.config) - if tt.expectedErr != "" { - require.EqualError(t, err, tt.expectedErr) - return - } - require.NoError(t, err) - - require.Equal(t, tt.expectGitlabNil, domains.gitlab == nil, "mismatch gitlab nil") - require.Equal(t, tt.expectDiskNil, domains.disk == nil, "mismatch disk nil") - }) - } -} - func TestGetDomain(t *testing.T) { t.Run("when requesting an existing domain for gitlab source", func(t *testing.T) { testDomain := "new-source-test.gitlab.io" @@ -112,24 +19,7 @@ func TestGetDomain(t *testing.T) { Once() defer newSource.AssertExpectations(t) - domains := newTestDomains(t, newSource, sourceGitlab) - - domain, err := domains.GetDomain(context.Background(), testDomain) - require.NoError(t, err) - require.NotNil(t, domain) - }) - - t.Run("when requesting an existing domain for auto source", func(t *testing.T) { - testDomain := "new-source-test.gitlab.io" - - newSource := NewMockSource() - newSource.On("GetDomain", testDomain). - Return(&domain.Domain{Name: testDomain}, nil). - Once() - newSource.On("IsReady").Return(true).Once() - defer newSource.AssertExpectations(t) - - domains := newTestDomains(t, newSource, sourceAuto) + domains := newTestDomains(t, newSource) domain, err := domains.GetDomain(context.Background(), testDomain) require.NoError(t, err) @@ -144,7 +34,7 @@ func TestGetDomain(t *testing.T) { defer newSource.AssertExpectations(t) - domains := newTestDomains(t, newSource, sourceGitlab) + domains := newTestDomains(t, newSource) domain, err := domains.GetDomain(context.Background(), "does-not-exist.test.io") require.NoError(t, err) @@ -152,12 +42,10 @@ func TestGetDomain(t *testing.T) { }) } -func newTestDomains(t *testing.T, gitlabSource *MockSource, config configSource) *Domains { +func newTestDomains(t *testing.T, gitlabSource *MockSource) *Domains { t.Helper() return &Domains{ - configSource: config, - gitlab: gitlabSource, - disk: disk.New(), + gitlab: gitlabSource, } } diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index c1074230..c8852976 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -242,7 +242,6 @@ func RunPagesProcess(t *testing.T, opts ...processOption) *LogCaptureBuffer { "-pages-root", wd, "-internal-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, - "-domain-config-source", "gitlab", ) logBuf, cleanup := runPagesProcess(t, processCfg.wait, processCfg.pagesBinary, processCfg.listeners, "", processCfg.envs, processCfg.extraArgs...) @@ -352,16 +351,6 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr args = append(args, "-metrics-address", promPort) } - // most of our acceptance tests still work only with disk source - // TODO: remove this with -domain-config-source flag itself along with daemon-enable-jail: - // https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 - // https://gitlab.com/gitlab-org/gitlab-pages/-/issues/561 - if !contains(extraArgs, "-domain-config-source") { - args = append(args, - "-domain-config-source", "disk", - ) - } - args = append(args, getPagesDaemonArgs(t)...) args = append(args, extraArgs...) diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index a4f3085b..238a05dd 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -4,8 +4,6 @@ import ( "fmt" "io/ioutil" "net/http" - "os" - "path" "strings" "testing" "time" @@ -106,51 +104,6 @@ func TestKnownHostReturns200(t *testing.T) { } } -// TODO: remove along with support for disk configuration https://gitlab.com/gitlab-org/gitlab-pages/-/issues/382 -func TestNestedSubgroups(t *testing.T) { - maxNestedSubgroup := 21 - - pagesRoot, err := ioutil.TempDir("", "pages-root") - require.NoError(t, err) - defer os.RemoveAll(pagesRoot) - - makeProjectIndex := func(subGroupPath string) { - projectPath := path.Join(pagesRoot, "nested", subGroupPath, "project", "public") - require.NoError(t, os.MkdirAll(projectPath, 0755)) - - projectIndex := path.Join(projectPath, "index.html") - require.NoError(t, ioutil.WriteFile(projectIndex, []byte("index"), 0644)) - } - makeProjectIndex("") - - paths := []string{""} - for i := 1; i < maxNestedSubgroup*2; i++ { - subGroupPath := fmt.Sprintf("%ssub%d/", paths[i-1], i) - paths = append(paths, subGroupPath) - - makeProjectIndex(subGroupPath) - } - - teardown := RunPagesProcessWithoutGitLabStub(t, *pagesBinary, supportedListeners(), "", "-pages-root", pagesRoot) - defer teardown() - - for nestingLevel, path := range paths { - t.Run(fmt.Sprintf("nested level %d", nestingLevel), func(t *testing.T) { - for _, spec := range supportedListeners() { - rsp, err := GetPageFromListener(t, spec, "nested.gitlab-example.com", path+"project/") - - require.NoError(t, err) - rsp.Body.Close() - if nestingLevel <= maxNestedSubgroup { - require.Equal(t, http.StatusOK, rsp.StatusCode) - } else { - require.Equal(t, http.StatusNotFound, rsp.StatusCode) - } - } - }) - } -} - func TestCustom404(t *testing.T) { RunPagesProcess(t) @@ -471,7 +424,7 @@ func TestDomainsSource(t *testing.T) { gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) - pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey, "-domain-config-source", tt.args.configSource} + pagesArgs := []string{"-gitlab-server", source.URL, "-api-secret-key", gitLabAPISecretKey} teardown := RunPagesProcessWithEnvs(t, true, *pagesBinary, []ListenSpec{httpListener}, "", []string{}, pagesArgs...) defer teardown() |