This is an example of how test data compares when using different levels of metricdatatest.AssertEqual
.
var tt.want metricsdata.Metrics
var rm metricsdata.ResourceMetrics // This was from Collect()
require.Len(t, rm.ScopeMetrics, 1)
sm := rm.ScopeMetrics[0]
require.Len(t, sm.Metrics, 1)
got := sm.Metrics[0]
metricdatatest.AssertEqual(t, tt.want, got, metricdatatest.IgnoreTimestamp())
--- FAIL: TestMeterCreatesInstruments/AyncFloat64Gauge (0.00s)
meter_test.go:292: [Name not equal:
expected: agauge2
actual: agauge]
var tt.want metricsdata.Metrics
var rm metricsdata.ResourceMetrics // This was from Collect()
want := metricdata.ResourceMetrics{
ScopeMetrics: []metricdata.ScopeMetrics{
{
Scope: instrumentation.Scope{Name: "testInstruments"},
Metrics: []metricdata.Metrics{
tt.want,
},
},
},
}
metricdatatest.AssertEqual(t, want, rm, metricdatatest.IgnoreTimestamp())
--- FAIL: TestMeterCreatesInstruments/AyncFloat64Gauge (0.00s)
meter_test.go:304: [ResourceMetrics ScopeMetrics not equal:
missing expected values:
metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"testInstruments", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"agauge2", Description:"", Unit:"", Data:metricdata.Gauge[float64]{DataPoints:[]metricdata.DataPoint[float64]{metricdata.DataPoint[float64]{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:interface {}(nil)}}, StartTime:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Value:11}}}}}}
unexpected additional values:
metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"testInstruments", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"agauge", Description:"", Unit:"", Data:metricdata.Gauge[float64]{DataPoints:[]metricdata.DataPoint[float64]{metricdata.DataPoint[float64]{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[0]attribute.KeyValue{}}}, StartTime:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Time:time.Date(2022, time.August, 19, 15, 53, 36, 960390100, time.Local), Value:11}}}}}}
]