Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client_stub.go « client « gitlab « source « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3879a33a98e92883c065f79f415d73e765059b6 (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"
	"time"

	"gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
)

// StubClient is a stubbed client used for testing
type StubClient struct {
	File string
}

// 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) Poll(r int, i time.Duration, errCh chan error) {
	errCh <- nil
}