diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-16 16:09:57 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-20 04:39:10 +0300 |
commit | fc9f9694567273ec72e65db3673495a1b8d24050 (patch) | |
tree | 4f491fd975fcd3bed53fc41bb8cb1e40d37327f6 /internal/source | |
parent | 8a8074fac85119724b68af4456264e15750643c6 (diff) |
test: remove domain-config-source=gitlab from test and remove tests using disk source
Diffstat (limited to 'internal/source')
-rw-r--r-- | internal/source/domains.go | 4 | ||||
-rw-r--r-- | internal/source/domains_test.go | 120 |
2 files changed, 6 insertions, 118 deletions
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, } } |