Skip to content

Commit

Permalink
Minor change to doCompare (#3130)
Browse files Browse the repository at this point in the history
This change was a part of #2964 but it's closed now. Having typed
arguments make it easier to massage the arguments before comparing.
Contributing this change for future maintainers.
  • Loading branch information
rakyll committed May 7, 2021
1 parent ce9bd8a commit c1e3d47
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func verifyNumScrapeResults(t *testing.T, td *testData, mds []internaldata.Metri
}
}

func doCompare(name string, t *testing.T, want, got interface{}) {
func doCompare(name string, t *testing.T, want, got *internaldata.MetricsData) {
t.Run(name, func(t *testing.T) {
assert.EqualValues(t, want, got)
})
Expand Down Expand Up @@ -279,8 +279,18 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
ts1 := gotG1.Timeseries[0].Points[0].Timestamp
// set this timestamp to wantG1
wantG1.Timeseries[0].Points[0].Timestamp = ts1
doCompare("scrape1", t, wantG1, gotG1)

doCompare("scrape1", t,
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{wantG1},
},
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{gotG1},
},
)
// verify the 2nd metricData
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp
Expand Down Expand Up @@ -505,8 +515,18 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
ts1 := gotG1.Timeseries[0].Points[0].Timestamp
// set this timestamp to wantG1
wantG1.Timeseries[0].Points[0].Timestamp = ts1
doCompare("scrape1", t, wantG1, gotG1)

doCompare("scrape1", t,
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{wantG1},
},
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{gotG1},
},
)
// verify the 2nd metricData
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp
Expand Down Expand Up @@ -822,8 +842,18 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
ts1 := gotG1.Timeseries[0].Points[0].Timestamp
// set this timestamp to wantG1
wantG1.Timeseries[0].Points[0].Timestamp = ts1
doCompare("scrape1", t, wantG1, gotG1)

doCompare("scrape1", t,
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{wantG1},
},
&internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{gotG1},
},
)
// verify the 2nd metricData
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp
Expand Down

0 comments on commit c1e3d47

Please sign in to comment.