-
Notifications
You must be signed in to change notification settings - Fork 73
/
mock_nrdb_client.go
52 lines (41 loc) · 995 Bytes
/
mock_nrdb_client.go
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
43
44
45
46
47
48
49
50
51
52
package validation
import (
"context"
"errors"
"github.com/newrelic/newrelic-client-go/pkg/nrdb"
)
type MockNRDBClient struct {
results func() []nrdb.NRDBResult
attempts int
error string
}
func NewMockNRDBClient() *MockNRDBClient {
return &MockNRDBClient{
results: func() []nrdb.NRDBResult {
return []nrdb.NRDBResult{}
},
}
}
func (c *MockNRDBClient) QueryWithContext(ctx context.Context, accountID int, nrql nrdb.NRQL) (*nrdb.NRDBResultContainer, error) {
c.attempts++
if c.error != "" {
return nil, errors.New(c.error)
}
return &nrdb.NRDBResultContainer{
Results: c.results(),
}, nil
}
func (c *MockNRDBClient) ThrowError(message string) {
c.error = message
}
func (c *MockNRDBClient) ReturnResultsAfterNAttempts(before []nrdb.NRDBResult, after []nrdb.NRDBResult, attempts int) {
c.results = func() []nrdb.NRDBResult {
if c.attempts < attempts {
return before
}
return after
}
}
func (c *MockNRDBClient) Attempts() int {
return c.attempts
}