Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/instance/configstore/mock.go
5363 views
1
package configstore
2
3
import (
4
"context"
5
6
"github.com/grafana/agent/pkg/metrics/instance"
7
)
8
9
// Mock is a Mock Store. Useful primarily for testing.
10
type Mock struct {
11
ListFunc func(ctx context.Context) ([]string, error)
12
GetFunc func(ctx context.Context, key string) (instance.Config, error)
13
PutFunc func(ctx context.Context, c instance.Config) (created bool, err error)
14
DeleteFunc func(ctx context.Context, key string) error
15
AllFunc func(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error)
16
WatchFunc func() <-chan WatchEvent
17
CloseFunc func() error
18
}
19
20
// List implements Store.
21
func (s *Mock) List(ctx context.Context) ([]string, error) {
22
if s.ListFunc != nil {
23
return s.ListFunc(ctx)
24
}
25
panic("List not implemented")
26
}
27
28
// Get implements Store.
29
func (s *Mock) Get(ctx context.Context, key string) (instance.Config, error) {
30
if s.GetFunc != nil {
31
return s.GetFunc(ctx, key)
32
}
33
panic("Get not implemented")
34
}
35
36
// Put implements Store.
37
func (s *Mock) Put(ctx context.Context, c instance.Config) (created bool, err error) {
38
if s.PutFunc != nil {
39
return s.PutFunc(ctx, c)
40
}
41
panic("Put not implemented")
42
}
43
44
// Delete implements Store.
45
func (s *Mock) Delete(ctx context.Context, key string) error {
46
if s.DeleteFunc != nil {
47
return s.DeleteFunc(ctx, key)
48
}
49
panic("Delete not implemented")
50
}
51
52
// All implements Store.
53
func (s *Mock) All(ctx context.Context, keep func(key string) bool) (<-chan instance.Config, error) {
54
if s.AllFunc != nil {
55
return s.AllFunc(ctx, keep)
56
}
57
panic("All not implemented")
58
}
59
60
// Watch implements Store.
61
func (s *Mock) Watch() <-chan WatchEvent {
62
if s.WatchFunc != nil {
63
return s.WatchFunc()
64
}
65
panic("Watch not implemented")
66
}
67
68
// Close implements Store.
69
func (s *Mock) Close() error {
70
if s.CloseFunc != nil {
71
return s.CloseFunc()
72
}
73
panic("Close not implemented")
74
}
75
76