Skip to content

Commit

Permalink
chore: modify wantLastValueMetric() to verify the last value of a metric
Browse files Browse the repository at this point in the history
  • Loading branch information
rhatgadkar-goog committed Oct 1, 2024
1 parent 4aa27a5 commit f96409c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ func dump[T any](t *testing.T, data T) string {
}

// wantLastValueMetric ensures the provided metrics include a metric with the
// wanted name and at least data point.
// wanted name and wanted value.
func wantLastValueMetric(t *testing.T, wantName string, ms []metric, wantValue int) {
t.Helper()
gotNames := make(map[string]view.AggregationData)
for _, m := range ms {
gotNames[m.name] = m.data
d, ok := m.data.(*view.LastValueData)
if ok && m.name == wantName && d.Value == float64(wantValue) {
return
}
ad, ok := gotNames[wantName]
if ok {
lvd, ok := ad.(*view.LastValueData)
if ok {
if lvd.Value == float64(wantValue) {
return
}
}
}
t.Fatalf(
Expand Down

0 comments on commit f96409c

Please sign in to comment.