diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-11-26 17:22:02 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-11-26 17:22:02 +0300 |
commit | 204b225d2308a61586ad7557d1f2f86bebfe73e6 (patch) | |
tree | f06a8f725fc2f5f5bb78ddd165d4c716fbe35324 /internal/source/domains_test.go | |
parent | 806c6dcec76021c78026dc0301331dbe983a938d (diff) |
Make new gitlab domains source more testable
Diffstat (limited to 'internal/source/domains_test.go')
-rw-r--r-- | internal/source/domains_test.go | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/internal/source/domains_test.go b/internal/source/domains_test.go index 74ac84c6..5125f462 100644 --- a/internal/source/domains_test.go +++ b/internal/source/domains_test.go @@ -4,28 +4,17 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitlab-pages/internal/domain" "gitlab.com/gitlab-org/gitlab-pages/internal/source/disk" ) -type mockSource struct { - mock.Mock -} - -func (m *mockSource) GetDomain(name string) (*domain.Domain, error) { - args := m.Called(name) - - return args.Get(0).(*domain.Domain), args.Error(1) -} - func TestHasDomain(t *testing.T) { testDomain := newSourceDomains[0] t.Run("when requesting a test domain", func(t *testing.T) { - newSource := new(mockSource) + newSource := NewMockSource() newSource.On("GetDomain", testDomain). Return(&domain.Domain{Name: testDomain}, nil). Once() @@ -40,7 +29,7 @@ func TestHasDomain(t *testing.T) { }) t.Run("when requesting a non-test domain", func(t *testing.T) { - newSource := new(mockSource) + newSource := NewMockSource() defer newSource.AssertExpectations(t) domains := &Domains{ @@ -55,7 +44,7 @@ func TestHasDomain(t *testing.T) { }) t.Run("when requesting a broken test domain", func(t *testing.T) { - newSource := new(mockSource) + newSource := NewMockSource() defer newSource.AssertExpectations(t) domains := &Domains{ |