blob: de6161e62fd46833fcb961eb293a2da0834b9014 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package client
import (
"context"
"encoding/json"
"os"
"gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
)
// StubClient is a stubbed client used for testing
type StubClient struct {
File string
StatusErr func() error
}
// Resolve implements api.Resolver
func (c StubClient) Resolve(ctx context.Context, host string) *api.Lookup {
lookup := c.GetLookup(ctx, host)
return &lookup
}
// GetLookup reads a test fixture and unmarshalls it
func (c StubClient) GetLookup(ctx context.Context, host string) api.Lookup {
lookup := api.Lookup{Name: host}
f, err := os.Open(c.File)
if err != nil {
lookup.Error = err
return lookup
}
defer f.Close()
lookup.Error = json.NewDecoder(f).Decode(&lookup.Domain)
return lookup
}
func (c StubClient) Status() error {
return c.StatusErr()
}
|