diff options
author | Vladimir Shushlin <vshushlin@gitlab.com> | 2020-08-04 12:02:38 +0300 |
---|---|---|
committer | Vladimir Shushlin <vshushlin@gitlab.com> | 2020-08-04 12:02:38 +0300 |
commit | 4a4d5746fca079a59204ef4ef738367a9a150660 (patch) | |
tree | 7ee2faa60dd72dae5029033f200b1a8e22735f2b | |
parent | 185e0a0e5c621f350335495291c535e5c05df89b (diff) |
Revert "Merge branch 'add-polling-to-domain-package' into 'master'"revert-b3bf3ac4
This reverts merge request !306
-rw-r--r-- | internal/source/domains.go | 17 | ||||
-rw-r--r-- | internal/source/domains_test.go | 42 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 8 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab_poll.go | 1 | ||||
-rw-r--r-- | internal/source/source.go | 1 | ||||
-rw-r--r-- | internal/source/source_mock.go | 6 |
6 files changed, 29 insertions, 46 deletions
diff --git a/internal/source/domains.go b/internal/source/domains.go index ca2a8b6e..77e1aa1d 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -44,22 +44,19 @@ func NewDomains(config Config) (*Domains, error) { // TODO: choose domain source config via config.DomainConfigSource() // https://gitlab.com/gitlab-org/gitlab/-/issues/217912 - domains := &Domains{ - disk: disk.New(), - } - if len(config.InternalGitLabServerURL()) == 0 || len(config.GitlabAPISecret()) == 0 { - return domains, nil + return &Domains{disk: disk.New()}, nil } - glClient, err := gitlab.New(config) + gitlab, err := gitlab.New(config) if err != nil { return nil, err } - domains.gitlab = glClient - - return domains, nil + return &Domains{ + gitlab: gitlab, + disk: disk.New(), + }, nil } // GetDomain retrieves a domain information from a source. We are using two @@ -88,7 +85,7 @@ func (d *Domains) IsReady() bool { } func (d *Domains) source(domain string) Source { - if d.gitlab == nil || !d.gitlab.IsReady() { + if d.gitlab == nil { return d.disk } diff --git a/internal/source/domains_test.go b/internal/source/domains_test.go index 2382e756..24008b08 100644 --- a/internal/source/domains_test.go +++ b/internal/source/domains_test.go @@ -65,21 +65,24 @@ func TestGetDomain(t *testing.T) { 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) + domains := &Domains{ + disk: disk.New(), + gitlab: newSource, + } domains.GetDomain(testDomain) }) t.Run("when requesting a non-test domain", func(t *testing.T) { newSource := NewMockSource() - newSource.On("IsReady").Return(true).Once() - defer newSource.AssertExpectations(t) - domains := newTestDomains(t, newSource) + domains := &Domains{ + disk: disk.New(), + gitlab: newSource, + } domain, err := domains.GetDomain("domain.test.io") @@ -91,7 +94,10 @@ func TestGetDomain(t *testing.T) { newSource := NewMockSource() defer newSource.AssertExpectations(t) - domains := newTestDomains(t, newSource) + domains := &Domains{ + disk: disk.New(), + gitlab: newSource, + } domain, err := domains.GetDomain("pages-broken-poc.gitlab.io") @@ -116,11 +122,12 @@ func TestGetDomain(t *testing.T) { 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) + domains := &Domains{ + disk: disk.New(), + gitlab: newSource, + } domains.GetDomain(testDomain) }) @@ -149,6 +156,8 @@ func TestGetDomainWithIncrementalrolloutOfGitLabSource(t *testing.T) { // Generates FNV 2643293380, 2643293380 % 100 = 80 domain80 := "test-domain-b.com" + diskSource := disk.New() + gitlabSourceConfig.Domains.Rollout.Percentage = 80 type testDomain struct { @@ -192,10 +201,12 @@ func TestGetDomainWithIncrementalrolloutOfGitLabSource(t *testing.T) { Once() } } - gitlabSource.On("IsReady").Return(true) defer gitlabSource.AssertExpectations(t) - domains := newTestDomains(t, gitlabSource) + domains := &Domains{ + disk: diskSource, + gitlab: gitlabSource, + } gitlabSourceConfig.Domains.Rollout.Stickiness = tc.stickiness @@ -206,12 +217,3 @@ func TestGetDomainWithIncrementalrolloutOfGitLabSource(t *testing.T) { }) } } - -func newTestDomains(t *testing.T, gitlabSource *MockSource) *Domains { - t.Helper() - - return &Domains{ - disk: disk.New(), - gitlab: gitlabSource, - } -} diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index 2635d864..5bacb603 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -104,11 +104,3 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { return &serving.Request{Serving: defaultServing()}, errors.New("could not match lookup path") } - -// IsReady returns the value of Gitlab `isReady` which is updated by `Poll`. -func (g *Gitlab) IsReady() bool { - g.mu.RLock() - defer g.mu.RUnlock() - - return g.isReady -} diff --git a/internal/source/gitlab/gitlab_poll.go b/internal/source/gitlab/gitlab_poll.go index 9fce7250..70644822 100644 --- a/internal/source/gitlab/gitlab_poll.go +++ b/internal/source/gitlab/gitlab_poll.go @@ -15,7 +15,6 @@ const ( // poll tries to call the /internal/pages/status API endpoint once plus // `retries` every `interval`. -// It updates the `isReady` value when successful. // TODO: Remove in https://gitlab.com/gitlab-org/gitlab/-/issues/218357 func (g *Gitlab) poll(retries int, interval time.Duration) { var err error diff --git a/internal/source/source.go b/internal/source/source.go index 5540066c..4b43b8f4 100644 --- a/internal/source/source.go +++ b/internal/source/source.go @@ -5,5 +5,4 @@ import "gitlab.com/gitlab-org/gitlab-pages/internal/domain" // Source represents an abstract interface of a domains configuration source. type Source interface { GetDomain(string) (*domain.Domain, error) - IsReady() bool } diff --git a/internal/source/source_mock.go b/internal/source/source_mock.go index 7c693eb1..ee24d804 100644 --- a/internal/source/source_mock.go +++ b/internal/source/source_mock.go @@ -18,12 +18,6 @@ func (m *MockSource) GetDomain(name string) (*domain.Domain, error) { return args.Get(0).(*domain.Domain), args.Error(1) } -func (m *MockSource) IsReady() bool { - args := m.Called() - - return args.Get(0).(bool) -} - // NewMockSource returns a new Source mock for testing func NewMockSource() *MockSource { return &MockSource{} |