go.d remove duplicates in testing (#18435)
Ilya Mashchenko committed
Aug 29, 2024 at 13:08 UTC
0c00ae582d83ef26c98f119e49d3fca5310b8e82
19 files changed
+68
-316
src/go/plugin/go.d/modules/ap/ap_test.go
+4
-18
@@ -211,25 +211,11 @@ func TestAP_Collect(t *testing.T) {
211
mx := ap.Collect()
212
213
assert.Equal(t, test.wantMetrics, mx)
214
- assert.Equal(t, test.wantCharts, len(*ap.Charts()), "Charts")
215
- testMetricsHasAllChartsDims(t, ap, mx)
216
- })
217
- }
218
-}
214
220
-func testMetricsHasAllChartsDims(t *testing.T, ap *AP, mx map[string]int64) {
221
- for _, chart := range *ap.Charts() {
222
- if chart.Obsolete {
223
- continue
224
- }
225
- for _, dim := range chart.Dims {
226
- _, ok := mx[dim.ID]
227
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
228
- }
229
- for _, v := range chart.Vars {
230
- _, ok := mx[v.ID]
231
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
232
- }
215
+ assert.Equal(t, test.wantCharts, len(*ap.Charts()), "wantCharts")
216
+
217
+ module.TestMetricsHasAllChartsDims(t, ap.Charts(), mx)
218
+ })
219
}
220
}
221
src/go/plugin/go.d/modules/clickhouse/clickhouse_test.go
+2
-13
@@ -243,25 +243,14 @@ func TestClickHouse_Collect(t *testing.T) {
243
mx := click.Collect()
244
245
require.Equal(t, test.wantMetrics, mx)
246
+
247
if len(test.wantMetrics) > 0 {
247
- testMetricsHasAllChartsDims(t, click, mx)
248
+ module.TestMetricsHasAllChartsDims(t, click.Charts(), mx)
249
}
250
})
251
}
252
}
253
253
-func testMetricsHasAllChartsDims(t *testing.T, click *ClickHouse, mx map[string]int64) {
254
- for _, chart := range *click.Charts() {
255
- if chart.Obsolete {
256
- continue
257
- }
258
- for _, dim := range chart.Dims {
259
- _, ok := mx[dim.ID]
260
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
261
- }
262
- }
263
-}
264
-
254
func prepareCaseOk(t *testing.T) (*ClickHouse, func()) {
255
t.Helper()
256
srv := httptest.NewServer(http.HandlerFunc(
src/go/plugin/go.d/modules/cockroachdb/cockroachdb_test.go
+5
-20
@@ -221,9 +221,11 @@ func TestCockroachDB_Collect(t *testing.T) {
221
"valcount": 124081,
222
}
223
224
- collected := cdb.Collect()
225
- assert.Equal(t, expected, collected)
226
- testCharts(t, cdb, collected)
224
+ mx := cdb.Collect()
225
+
226
+ assert.Equal(t, expected, mx)
227
+
228
+ module.TestMetricsHasAllChartsDims(t, cdb.Charts(), mx)
229
}
230
231
func TestCockroachDB_Collect_ReturnsNilIfNotCockroachDBMetrics(t *testing.T) {
@@ -254,23 +256,6 @@ func TestCockroachDB_Collect_ReturnsNilIfReceiveResponse404(t *testing.T) {
256
assert.Nil(t, cdb.Collect())
257
}
258
257
-func testCharts(t *testing.T, cdb *CockroachDB, collected map[string]int64) {
258
- ensureCollectedHasAllChartsDimsVarsIDs(t, cdb, collected)
259
-}
260
-
261
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, c *CockroachDB, collected map[string]int64) {
262
- for _, chart := range *c.Charts() {
263
- for _, dim := range chart.Dims {
264
- _, ok := collected[dim.ID]
265
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
266
- }
267
- for _, v := range chart.Vars {
268
- _, ok := collected[v.ID]
269
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
270
- }
271
- }
272
-}
273
-
259
func prepareCockroachDB() *CockroachDB {
260
cdb := New()
261
cdb.URL = "http://127.0.0.1:38001/metrics"
src/go/plugin/go.d/modules/dmcache/dmcache_test.go
+4
-14
@@ -192,21 +192,11 @@ func TestLVM_Collect(t *testing.T) {
192
mx := dmcache.Collect()
193
194
assert.Equal(t, test.wantMetrics, mx)
195
- assert.Len(t, *dmcache.Charts(), test.wantCharts)
196
- testMetricsHasAllChartsDims(t, dmcache, mx)
197
- })
198
- }
199
-}
195
201
-func testMetricsHasAllChartsDims(t *testing.T, dmcache *DmCache, mx map[string]int64) {
202
- for _, chart := range *dmcache.Charts() {
203
- if chart.Obsolete {
204
- continue
205
- }
206
- for _, dim := range chart.Dims {
207
- _, ok := mx[dim.ID]
208
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
209
- }
196
+ assert.Len(t, *dmcache.Charts(), test.wantCharts, "wantCharts")
197
+
198
+ module.TestMetricsHasAllChartsDims(t, dmcache.Charts(), mx)
199
+ })
200
}
201
}
202
src/go/plugin/go.d/modules/fail2ban/fail2ban_test.go
+4
-18
@@ -170,30 +170,16 @@ func TestFail2Ban_Collect(t *testing.T) {
170
mx := f2b.Collect()
171
172
assert.Equal(t, test.wantMetrics, mx)
173
+
174
if len(test.wantMetrics) > 0 {
174
- assert.Len(t, *f2b.Charts(), len(jailChartsTmpl)*2)
175
- testMetricsHasAllChartsDims(t, f2b, mx)
175
+ assert.Len(t, *f2b.Charts(), len(jailChartsTmpl)*2, "wantCharts")
176
+
177
+ module.TestMetricsHasAllChartsDims(t, f2b.Charts(), mx)
178
}
179
})
180
}
181
}
182
181
-func testMetricsHasAllChartsDims(t *testing.T, f2b *Fail2Ban, mx map[string]int64) {
182
- for _, chart := range *f2b.Charts() {
183
- if chart.Obsolete {
184
- continue
185
- }
186
- for _, dim := range chart.Dims {
187
- _, ok := mx[dim.ID]
188
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
189
- }
190
- for _, v := range chart.Vars {
191
- _, ok := mx[v.ID]
192
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
193
- }
194
- }
195
-}
196
-
183
func prepareMockOk() *mockFail2BanClientCliExec {
184
return &mockFail2BanClientCliExec{
185
statusData: dataStatus,
src/go/plugin/go.d/modules/filecheck/filecheck_test.go
+3
-13
@@ -244,21 +244,11 @@ func TestFilecheck_Collect(t *testing.T) {
244
mx := fc.Collect()
245
246
copyModTime(test.wantCollected, mx)
247
+
248
assert.Equal(t, test.wantCollected, mx)
248
- testMetricsHasAllChartsDims(t, fc, mx)
249
- })
250
- }
251
-}
249
253
-func testMetricsHasAllChartsDims(t *testing.T, fc *Filecheck, mx map[string]int64) {
254
- for _, chart := range *fc.Charts() {
255
- if chart.Obsolete {
256
- continue
257
- }
258
- for _, dim := range chart.Dims {
259
- _, ok := mx[dim.ID]
260
- assert.Truef(t, ok, "mx metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
261
- }
250
+ module.TestMetricsHasAllChartsDims(t, fc.Charts(), mx)
251
+ })
252
}
253
}
254
src/go/plugin/go.d/modules/hddtemp/hddtemp_test.go
+6
-19
@@ -242,26 +242,13 @@ func TestHddTemp_Collect(t *testing.T) {
242
mx := hdd.Collect()
243
244
assert.Equal(t, test.wantMetrics, mx)
245
- assert.Len(t, *hdd.Charts(), test.wantCharts)
246
- assert.Equal(t, test.wantDisconnect, mock.disconnectCalled)
247
- testMetricsHasAllChartsDims(t, hdd, mx)
248
- })
249
- }
250
-}
245
252
-func testMetricsHasAllChartsDims(t *testing.T, hdd *HddTemp, mx map[string]int64) {
253
- for _, chart := range *hdd.Charts() {
254
- if chart.Obsolete {
255
- continue
256
- }
257
- for _, dim := range chart.Dims {
258
- _, ok := mx[dim.ID]
259
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
260
- }
261
- for _, v := range chart.Vars {
262
- _, ok := mx[v.ID]
263
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
264
- }
246
+ assert.Len(t, *hdd.Charts(), test.wantCharts, "wantCharts")
247
+
248
+ assert.Equal(t, test.wantDisconnect, mock.disconnectCalled, "disconnectCalled")
249
+
250
+ module.TestMetricsHasAllChartsDims(t, hdd.Charts(), mx)
251
+ })
252
}
253
}
254
src/go/plugin/go.d/modules/hpssa/hpssa_test.go
+4
-18
@@ -352,8 +352,10 @@ func TestHpssa_Collect(t *testing.T) {
352
mx := hpe.Collect()
353
354
assert.Equal(t, test.wantMetrics, mx)
355
- assert.Len(t, *hpe.Charts(), test.wantCharts)
356
- testMetricsHasAllChartsDims(t, hpe, mx)
355
+
356
+ assert.Len(t, *hpe.Charts(), test.wantCharts, "wantCharts")
357
+
358
+ module.TestMetricsHasAllChartsDims(t, hpe.Charts(), mx)
359
})
360
}
361
}
@@ -412,19 +414,3 @@ func (m *mockSsacliExec) controllersInfo() ([]byte, error) {
414
}
415
return m.infoData, nil
416
}
415
-
416
-func testMetricsHasAllChartsDims(t *testing.T, hpe *Hpssa, mx map[string]int64) {
417
- for _, chart := range *hpe.Charts() {
418
- if chart.Obsolete {
419
- continue
420
- }
421
- for _, dim := range chart.Dims {
422
- _, ok := mx[dim.ID]
423
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
424
- }
425
- for _, v := range chart.Vars {
426
- _, ok := mx[v.ID]
427
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
428
- }
429
- }
430
-}
src/go/plugin/go.d/modules/ipfs/ipfs_test.go
+2
-17
@@ -165,29 +165,14 @@ func TestIPFS_Collect(t *testing.T) {
165
mx := ipfs.Collect()
166
167
require.Equal(t, test.wantMetrics, mx)
168
+
169
if len(test.wantMetrics) > 0 {
169
- testMetricsHasAllChartsDims(t, ipfs, mx)
170
+ module.TestMetricsHasAllChartsDims(t, ipfs.Charts(), mx)
171
}
172
})
173
}
174
}
175
175
-func testMetricsHasAllChartsDims(t *testing.T, ipfs *IPFS, mx map[string]int64) {
176
- for _, chart := range *ipfs.Charts() {
177
- if chart.Obsolete {
178
- continue
179
- }
180
- for _, dim := range chart.Dims {
181
- _, ok := mx[dim.ID]
182
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
183
- }
184
- for _, v := range chart.Vars {
185
- _, ok := mx[v.ID]
186
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
187
- }
188
- }
189
-}
190
-
176
func prepareCaseOkDefault(t *testing.T) (*IPFS, func()) {
177
t.Helper()
178
srv := httptest.NewServer(http.HandlerFunc(
src/go/plugin/go.d/modules/litespeed/litespeed_test.go
+2
-17
@@ -128,29 +128,14 @@ func TestLitespeed_Collect(t *testing.T) {
128
mx := lite.Collect()
129
130
assert.Equal(t, test.wantMetrics, mx)
131
+
132
if len(test.wantMetrics) > 0 {
132
- testMetricsHasAllChartsDims(t, lite, mx)
133
+ module.TestMetricsHasAllChartsDims(t, lite.Charts(), mx)
134
}
135
})
136
}
137
}
138
138
-func testMetricsHasAllChartsDims(t *testing.T, lite *Litespeed, mx map[string]int64) {
139
- for _, chart := range *lite.Charts() {
140
- if chart.Obsolete {
141
- continue
142
- }
143
- for _, dim := range chart.Dims {
144
- _, ok := mx[dim.ID]
145
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
146
- }
147
- for _, v := range chart.Vars {
148
- _, ok := mx[v.ID]
149
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
150
- }
151
- }
152
-}
153
-
139
func prepareLitespeedOk() *Litespeed {
140
lite := New()
141
lite.ReportsDir = "testdata"
src/go/plugin/go.d/modules/puppet/puppet_test.go
+2
-17
@@ -151,29 +151,14 @@ func TestPuppet_Collect(t *testing.T) {
151
mx := puppet.Collect()
152
153
require.Equal(t, test.wantMetrics, mx)
154
+
155
if len(test.wantMetrics) > 0 {
155
- testMetricsHasAllChartsDims(t, puppet, mx)
156
+ module.TestMetricsHasAllChartsDims(t, puppet.Charts(), mx)
157
}
158
})
159
}
160
}
161
161
-func testMetricsHasAllChartsDims(t *testing.T, puppet *Puppet, mx map[string]int64) {
162
- for _, chart := range *puppet.Charts() {
163
- if chart.Obsolete {
164
- continue
165
- }
166
- for _, dim := range chart.Dims {
167
- _, ok := mx[dim.ID]
168
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
169
- }
170
- for _, v := range chart.Vars {
171
- _, ok := mx[v.ID]
172
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
173
- }
174
- }
175
-}
176
-
162
func prepareCaseOkDefault(t *testing.T) (*Puppet, func()) {
163
t.Helper()
164
srv := httptest.NewServer(http.HandlerFunc(
src/go/plugin/go.d/modules/rspamd/rspamd_test.go
+2
-17
@@ -156,29 +156,14 @@ func TestRspamd_Collect(t *testing.T) {
156
mx := rsp.Collect()
157
158
require.Equal(t, test.wantMetrics, mx)
159
+
160
if len(test.wantMetrics) > 0 {
160
- testMetricsHasAllChartsDims(t, rsp, mx)
161
+ module.TestMetricsHasAllChartsDims(t, rsp.Charts(), mx)
162
}
163
})
164
}
165
}
166
166
-func testMetricsHasAllChartsDims(t *testing.T, rsp *Rspamd, mx map[string]int64) {
167
- for _, chart := range *rsp.Charts() {
168
- if chart.Obsolete {
169
- continue
170
- }
171
- for _, dim := range chart.Dims {
172
- _, ok := mx[dim.ID]
173
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
174
- }
175
- for _, v := range chart.Vars {
176
- _, ok := mx[v.ID]
177
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
178
- }
179
- }
180
-}
181
-
167
func prepareCaseOk(t *testing.T) (*Rspamd, func()) {
168
t.Helper()
169
srv := httptest.NewServer(http.HandlerFunc(
src/go/plugin/go.d/modules/scaleio/scaleio_test.go
+6
-17
@@ -298,9 +298,11 @@ func TestScaleIO_Collect(t *testing.T) {
298
"system_total_iops_write": 617200,
299
}
300
301
- collected := scaleIO.Collect()
302
- assert.Equal(t, expected, collected)
303
- testCharts(t, scaleIO, collected)
301
+ mx := scaleIO.Collect()
302
+
303
+ assert.Equal(t, expected, mx)
304
+
305
+ testCharts(t, scaleIO, mx)
306
}
307
308
func TestScaleIO_Collect_ConnectionRefused(t *testing.T) {
@@ -317,7 +319,7 @@ func testCharts(t *testing.T, scaleIO *ScaleIO, collected map[string]int64) {
319
t.Helper()
320
ensureStoragePoolChartsAreCreated(t, scaleIO)
321
ensureSdcChartsAreCreated(t, scaleIO)
320
- ensureCollectedHasAllChartsDimsVarsIDs(t, scaleIO, collected)
322
+ module.TestMetricsHasAllChartsDims(t, scaleIO.Charts(), collected)
323
}
324
325
func ensureStoragePoolChartsAreCreated(t *testing.T, scaleIO *ScaleIO) {
@@ -336,19 +338,6 @@ func ensureSdcChartsAreCreated(t *testing.T, scaleIO *ScaleIO) {
338
}
339
}
340
339
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, scaleIO *ScaleIO, collected map[string]int64) {
340
- for _, chart := range *scaleIO.Charts() {
341
- for _, dim := range chart.Dims {
342
- _, ok := collected[dim.ID]
343
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
344
- }
345
- for _, v := range chart.Vars {
346
- _, ok := collected[v.ID]
347
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
348
- }
349
- }
350
-}
351
-
341
func prepareSrvMockScaleIO(t *testing.T) (*httptest.Server, *client.MockScaleIOAPIServer, *ScaleIO) {
342
t.Helper()
343
const (
src/go/plugin/go.d/modules/smartctl/smartctl_test.go
+4
-18
@@ -366,25 +366,11 @@ func TestSmartctl_Collect(t *testing.T) {
366
}
367
368
assert.Equal(t, test.wantMetrics, mx)
369
- assert.Len(t, *smart.Charts(), test.wantCharts)
370
- testMetricsHasAllChartsDims(t, smart, mx)
371
- })
372
- }
373
-}
369
375
-func testMetricsHasAllChartsDims(t *testing.T, smart *Smartctl, mx map[string]int64) {
376
- for _, chart := range *smart.Charts() {
377
- if chart.Obsolete {
378
- continue
379
- }
380
- for _, dim := range chart.Dims {
381
- _, ok := mx[dim.ID]
382
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
383
- }
384
- for _, v := range chart.Vars {
385
- _, ok := mx[v.ID]
386
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
387
- }
370
+ assert.Len(t, *smart.Charts(), test.wantCharts, "wantCharts")
371
+
372
+ module.TestMetricsHasAllChartsDims(t, smart.Charts(), mx)
373
+ })
374
}
375
}
376
src/go/plugin/go.d/modules/squidlog/squidlog_test.go
+7
-18
@@ -238,16 +238,18 @@ func TestSquidLog_Collect_ReturnOldDataIfNothingRead(t *testing.T) {
238
}
239
240
_ = squid.Collect()
241
- collected := squid.Collect()
241
243
- assert.Equal(t, expected, collected)
244
- testCharts(t, squid, collected)
242
+ mx := squid.Collect()
243
+
244
+ assert.Equal(t, expected, mx)
245
+
246
+ testCharts(t, squid, mx)
247
}
248
247
-func testCharts(t *testing.T, squidlog *SquidLog, collected map[string]int64) {
249
+func testCharts(t *testing.T, squidlog *SquidLog, mx map[string]int64) {
250
t.Helper()
251
ensureChartsDynamicDimsCreated(t, squidlog)
250
- ensureCollectedHasAllChartsDimsVarsIDs(t, squidlog, collected)
252
+ module.TestMetricsHasAllChartsDims(t, squidlog.Charts(), mx)
253
}
254
255
func ensureChartsDynamicDimsCreated(t *testing.T, squid *SquidLog) {
@@ -276,19 +278,6 @@ func ensureDynamicDimsCreated(t *testing.T, squid *SquidLog, chartID, dimPrefix
278
}
279
}
280
279
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, s *SquidLog, collected map[string]int64) {
280
- for _, chart := range *s.Charts() {
281
- for _, dim := range chart.Dims {
282
- _, ok := collected[dim.ID]
283
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
284
- }
285
- for _, v := range chart.Vars {
286
- _, ok := collected[v.ID]
287
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
288
- }
289
- }
290
-}
291
-
281
func prepareSquidCollect(t *testing.T) *SquidLog {
282
t.Helper()
283
squid := New()
src/go/plugin/go.d/modules/storcli/storcli_test.go
+4
-18
@@ -230,8 +230,10 @@ func TestStorCli_Collect(t *testing.T) {
230
mx := stor.Collect()
231
232
assert.Equal(t, test.wantMetrics, mx)
233
- assert.Len(t, *stor.Charts(), test.wantCharts)
234
- testMetricsHasAllChartsDims(t, stor, mx)
233
+
234
+ assert.Len(t, *stor.Charts(), test.wantCharts, "wantCharts")
235
+
236
+ module.TestMetricsHasAllChartsDims(t, stor.Charts(), mx)
237
})
238
}
239
}
@@ -291,19 +293,3 @@ func (m *mockStorCliExec) drivesInfo() ([]byte, error) {
293
}
294
return m.drivesInfoData, nil
295
}
294
-
295
-func testMetricsHasAllChartsDims(t *testing.T, stor *StorCli, mx map[string]int64) {
296
- for _, chart := range *stor.Charts() {
297
- if chart.Obsolete {
298
- continue
299
- }
300
- for _, dim := range chart.Dims {
301
- _, ok := mx[dim.ID]
302
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
303
- }
304
- for _, v := range chart.Vars {
305
- _, ok := mx[v.ID]
306
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
307
- }
308
- }
309
-}
src/go/plugin/go.d/modules/vernemq/vernemq_test.go
+5
-20
@@ -91,9 +91,11 @@ func TestVerneMQ_Collect(t *testing.T) {
91
verneMQ, srv := prepareClientServerV1101(t)
92
defer srv.Close()
93
94
- collected := verneMQ.Collect()
95
- assert.Equal(t, v1101ExpectedMetrics, collected)
96
- testCharts(t, verneMQ, collected)
94
+ mx := verneMQ.Collect()
95
+
96
+ assert.Equal(t, v1101ExpectedMetrics, mx)
97
+
98
+ module.TestMetricsHasAllChartsDims(t, verneMQ.Charts(), mx)
99
}
100
101
func TestVerneMQ_Collect_ReturnsNilIfConnectionRefused(t *testing.T) {
@@ -124,23 +126,6 @@ func TestVerneMQ_Collect_ReturnsNilIfReceiveResponse404(t *testing.T) {
126
assert.Nil(t, verneMQ.Collect())
127
}
128
127
-func testCharts(t *testing.T, verneMQ *VerneMQ, collected map[string]int64) {
128
- ensureCollectedHasAllChartsDimsVarsIDs(t, verneMQ, collected)
129
-}
130
-
131
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, verneMQ *VerneMQ, collected map[string]int64) {
132
- for _, chart := range *verneMQ.Charts() {
133
- for _, dim := range chart.Dims {
134
- _, ok := collected[dim.ID]
135
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
136
- }
137
- for _, v := range chart.Vars {
138
- _, ok := collected[v.ID]
139
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
140
- }
141
- }
142
-}
143
-
129
func prepareVerneMQ() *VerneMQ {
130
verneMQ := New()
131
verneMQ.URL = "http://127.0.0.1:38001/metrics"
src/go/plugin/go.d/modules/weblog/weblog_test.go
+1
-10
@@ -737,16 +737,7 @@ func testCharts(t *testing.T, w *WebLog, mx map[string]int64) {
737
testCustomTimeFieldCharts(t, w)
738
testCustomNumericFieldCharts(t, w)
739
740
- testChartsDimIDs(t, w, mx)
741
-}
742
-
743
-func testChartsDimIDs(t *testing.T, w *WebLog, mx map[string]int64) {
744
- for _, chart := range *w.Charts() {
745
- for _, dim := range chart.Dims {
746
- _, ok := mx[dim.ID]
747
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
748
- }
749
- }
740
+ module.TestMetricsHasAllChartsDims(t, w.Charts(), mx)
741
}
742
743
func testVhostChart(t *testing.T, w *WebLog) {
src/go/plugin/go.d/modules/windows/windows_test.go
+1
-14
@@ -817,7 +817,7 @@ func TestWindows_Collect(t *testing.T) {
817
818
func testCharts(t *testing.T, win *Windows, mx map[string]int64) {
819
ensureChartsDimsCreated(t, win)
820
- ensureCollectedHasAllChartsDimsVarsIDs(t, win, mx)
820
+ module.TestMetricsHasAllChartsDims(t, win.Charts(), mx)
821
}
822
823
func ensureChartsDimsCreated(t *testing.T, w *Windows) {
@@ -1047,19 +1047,6 @@ func ensureChartsDimsCreated(t *testing.T, w *Windows) {
1047
}
1048
}
1049
1050
-func ensureCollectedHasAllChartsDimsVarsIDs(t *testing.T, w *Windows, mx map[string]int64) {
1051
- for _, chart := range *w.Charts() {
1052
- for _, dim := range chart.Dims {
1053
- _, ok := mx[dim.ID]
1054
- assert.Truef(t, ok, "collected metrics has no data for dim '%s' chart '%s'", dim.ID, chart.ID)
1055
- }
1056
- for _, v := range chart.Vars {
1057
- _, ok := mx[v.ID]
1058
- assert.Truef(t, ok, "collected metrics has no data for var '%s' chart '%s'", v.ID, chart.ID)
1059
- }
1060
- }
1061
-}
1062
-
1050
func prepareWindowsV0200() (win *Windows, cleanup func()) {
1051
ts := httptest.NewServer(http.HandlerFunc(
1052
func(w http.ResponseWriter, r *http.Request) {