generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mocks_test.go
203 lines (161 loc) · 3.95 KB
/
mocks_test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package ancla
import (
"context"
"errors"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/mock"
"github.com/xmidt-org/argus/chrysom"
"github.com/xmidt-org/argus/model"
)
var (
errReadBodyFail = errors.New("read test error")
errMockValidatorFail = errors.New("validation error")
)
type mockPushReader struct {
mock.Mock
}
func (m *mockPushReader) GetItems(ctx context.Context, owner string) (chrysom.Items, error) {
// nolint:typecheck
args := m.Called(ctx, owner)
return args.Get(0).(chrysom.Items), args.Error(1)
}
func (m *mockPushReader) Start(ctx context.Context) error {
// nolint:typecheck
args := m.Called(ctx)
return args.Error(0)
}
func (m *mockPushReader) Stop(ctx context.Context) error {
// nolint:typecheck
args := m.Called(ctx)
return args.Error(0)
}
func (m *mockPushReader) PushItem(ctx context.Context, owner string, item model.Item) (chrysom.PushResult, error) {
// nolint:typecheck
args := m.Called(ctx, owner, item)
return args.Get(0).(chrysom.PushResult), args.Error(1)
}
func (m *mockPushReader) RemoveItem(ctx context.Context, id, owner string) (model.Item, error) {
// nolint:typecheck
args := m.Called(ctx, id, owner)
return args.Get(0).(model.Item), args.Error(0)
}
type mockService struct {
mock.Mock
}
func (m *mockService) Add(ctx context.Context, owner string, iw InternalWebhook) error {
// nolint:typecheck
args := m.Called(ctx, owner, iw)
return args.Error(0)
}
func (m *mockService) GetAll(ctx context.Context) ([]InternalWebhook, error) {
// nolint:typecheck
args := m.Called(ctx)
return args.Get(0).([]InternalWebhook), args.Error(1)
}
type mockCounter struct {
mock.Mock
}
func (m *mockCounter) With(labelValues ...string) prometheus.Counter {
// nolint:typecheck
m.Called(interfacify(labelValues)...)
return m
}
func (m *mockCounter) Add(delta float64) {
// nolint:typecheck
m.Called(delta)
}
func (m *mockCounter) Inc() {
// nolint:typecheck
m.Called()
}
func (m *mockCounter) Write(out *dto.Metric) error {
// nolint:typecheck
m.Called()
return nil
}
func (m *mockCounter) Desc() *prometheus.Desc {
// nolint:typecheck
m.Called()
return &prometheus.Desc{}
}
func (m *mockCounter) Collect(ch chan<- prometheus.Metric) {
// nolint:typecheck
m.Called()
}
func (m *mockCounter) Describe(ch chan<- *prometheus.Desc) {
// nolint:typecheck
m.Called()
}
type mockGauge struct {
mock.Mock
}
func (m *mockGauge) With(labelValues ...string) prometheus.Gauge {
// nolint:typecheck
m.Called(interfacify(labelValues)...)
return m
}
func (m *mockGauge) Set(value float64) {
// nolint:typecheck
m.Called(value)
}
func (m *mockGauge) Add(delta float64) {
// nolint:typecheck
m.Called(delta)
}
func (m *mockGauge) Sub(value float64) {
// nolint:typecheck
m.Called(value)
}
func (m *mockGauge) SetToCurrentTime() {
// nolint:typecheck
m.Called()
}
func (m *mockGauge) Inc() {
// nolint:typecheck
m.Called()
}
func (m *mockGauge) Dec() {
// nolint:typecheck
m.Called()
}
func (m *mockGauge) Write(out *dto.Metric) error {
// nolint:typecheck
m.Called()
return nil
}
func (m *mockGauge) Desc() *prometheus.Desc {
// nolint:typecheck
m.Called()
return &prometheus.Desc{}
}
func (m *mockGauge) Collect(ch chan<- prometheus.Metric) {
// nolint:typecheck
m.Called()
}
func (m *mockGauge) Describe(ch chan<- *prometheus.Desc) {
// nolint:typecheck
m.Called()
}
func interfacify(vals []string) []interface{} {
transformed := make([]interface{}, len(vals))
for i, val := range vals {
transformed[i] = val
}
return transformed
}
type errReader struct {
}
func (e errReader) Read(p []byte) (n int, err error) {
return 0, errReadBodyFail
}
func (e errReader) Close() error {
return errors.New("close test error")
}
func mockValidator() ValidatorFunc {
return func(w Webhook) error {
return errMockValidatorFail
}
}