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/gitlab/client/client_stub.go | |
parent | 806c6dcec76021c78026dc0301331dbe983a938d (diff) |
Make new gitlab domains source more testable
Diffstat (limited to 'internal/source/gitlab/client/client_stub.go')
-rw-r--r-- | internal/source/gitlab/client/client_stub.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/source/gitlab/client/client_stub.go b/internal/source/gitlab/client/client_stub.go new file mode 100644 index 00000000..48dbf549 --- /dev/null +++ b/internal/source/gitlab/client/client_stub.go @@ -0,0 +1,31 @@ +package client + +import ( + "encoding/json" + "os" + + "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/domain" +) + +// StubClient is a stubbed client used for testing +type StubClient struct { + file string +} + +// GetVirtualDomain reads a test fixture and unmarshalls it +func (m *StubClient) GetVirtualDomain(host string) (domain *domain.VirtualDomain, err error) { + f, err := os.Open(m.file) + defer f.Close() + if err != nil { + return nil, err + } + + err = json.NewDecoder(f).Decode(&domain) + + return domain, err +} + +// NewStubClient return a stubbed client +func NewStubClient(fixture string) *StubClient { + return &StubClient{file: fixture} +} |