diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-02-16 10:00:46 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-03-18 03:20:19 +0300 |
commit | 4f597a45e15283cdefa66792575a6da602376ba2 (patch) | |
tree | 2d9a0791db7e196de4ed5eab94e5713cdeaaceac /internal | |
parent | ed2b1232009f50b54278cadae8c1a3659539fa4c (diff) |
Simplify mock
Diffstat (limited to 'internal')
-rw-r--r-- | internal/source/gitlab/cache/entry_test.go | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/internal/source/gitlab/cache/entry_test.go b/internal/source/gitlab/cache/entry_test.go index 59183785..528f2a6f 100644 --- a/internal/source/gitlab/cache/entry_test.go +++ b/internal/source/gitlab/cache/entry_test.go @@ -7,10 +7,9 @@ import ( "testing" "time" - "gitlab.com/gitlab-org/gitlab-pages/internal/domain" - "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitlab-pages/internal/domain" "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api" ) @@ -116,7 +115,7 @@ func TestEntryRefresh(t *testing.T) { require.Equal(t, storedEntry.Lookup(), entry.Lookup(), "lookup should be the same") }) - t.Run("entry is different after expiring", func(t *testing.T) { + t.Run("entry is different after it expired and calling refresh on it", func(t *testing.T) { client.failed = false entry := newCacheEntry("error.gitlab.io", cc.entryRefreshTimeout, cc.cacheExpiry, store.(*memstore).retriever) @@ -164,28 +163,22 @@ func (mm *lookupMock) GetLookup(ctx context.Context, domainName string) api.Look Name: domainName, } - select { - case <-ctx.Done(): - lookup.Error = ctx.Err() + lookup, ok := mm.responses[domainName] + if !ok { + lookup.Error = domain.ErrDomainDoesNotExist return lookup - default: - lookup, ok := mm.responses[domainName] - if !ok { - lookup.Error = domain.ErrDomainDoesNotExist - return lookup - } - - // return error after mm.successCount - mm.currentCount++ - if mm.currentCount > mm.successCount { - mm.currentCount = 0 - mm.failed = true - - lookup.Error = http.ErrServerClosed - } + } - return lookup + // return error after mm.successCount + mm.currentCount++ + if mm.currentCount > mm.successCount { + mm.currentCount = 0 + mm.failed = true + + lookup.Error = http.ErrServerClosed } + + return lookup } func (mm *lookupMock) Status() error { |