forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock.go
66 lines (48 loc) · 1.36 KB
/
mock.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package secretscan
import (
"context"
"github.com/grafana/grafana/pkg/services/apikey"
"github.com/grafana/grafana/pkg/services/serviceaccounts"
)
type MockTokenRetriever struct {
keys []apikey.APIKey
errList error
errRevoke error
listCalls []any
revokeCalls [][]any
}
func (m *MockTokenRetriever) ListTokens(
ctx context.Context, query *serviceaccounts.GetSATokensQuery,
) ([]apikey.APIKey, error) {
m.listCalls = append(m.listCalls, query)
return m.keys, m.errList
}
func (m *MockTokenRetriever) RevokeServiceAccountToken(
ctx context.Context, orgID, serviceAccountID, tokenID int64,
) error {
m.revokeCalls = append(m.revokeCalls, []any{orgID, serviceAccountID, tokenID})
return m.errRevoke
}
type MockSecretScaner struct{}
func (m *MockSecretScaner) CheckTokens(ctx context.Context) error {
return nil
}
type MockSecretScanClient struct {
tokens []Token
err error
checkCalls []any
}
func (m *MockSecretScanClient) CheckTokens(ctx context.Context, keyHashes []string) ([]Token, error) {
m.checkCalls = append(m.checkCalls, keyHashes)
return m.tokens, m.err
}
type MockSecretScanNotifier struct {
err error
notifyCalls [][]any
}
func (m *MockSecretScanNotifier) Notify(ctx context.Context,
token *Token, tokenName string, revoked bool,
) error {
m.notifyCalls = append(m.notifyCalls, []any{token, tokenName, revoked})
return m.err
}