Created
July 20, 2022 13:21
-
-
Save MadVikingGod/e6bd791c2747d9311b936ab31a6b1cdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright The OpenTelemetry Authors | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
//go:build go1.18 && tests_fail | |
// +build go1.18,tests_fail | |
package metricdatatest // import "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" | |
import ( | |
"testing" | |
) | |
func testFailDatatype[T Datatypes](a, b T) func(*testing.T) { | |
return func(t *testing.T) { | |
AssertEqual(t, a, b) | |
} | |
} | |
func TestFailAssertEqual(t *testing.T) { | |
t.Run("ResourceMetrics", testFailDatatype(resourceMetricsA, resourceMetricsB)) | |
t.Run("ScopeMetrics", testFailDatatype(scopeMetricsA, scopeMetricsB)) | |
t.Run("Metrics", testFailDatatype(metricsA, metricsB)) | |
t.Run("Histogram", testFailDatatype(histogramA, histogramB)) | |
t.Run("Sum", testFailDatatype(sumA, sumB)) | |
t.Run("Gauge", testFailDatatype(gaugeA, gaugeB)) | |
t.Run("HistogramDataPoint", testFailDatatype(histogramDataPointA, histogramDataPointB)) | |
t.Run("DataPoint", testFailDatatype(dataPointsA, dataPointsB)) | |
t.Run("Int64", testFailDatatype(int64A, int64B)) | |
t.Run("Float64", testFailDatatype(float64A, float64B)) | |
} | |
func TestFailAssertAggregationsEqual(t *testing.T) { | |
AssertAggregationsEqual(t, sumA, nil) | |
AssertAggregationsEqual(t, sumA, gaugeA) | |
AssertAggregationsEqual(t, unknownAggregation{}, unknownAggregation{}) | |
AssertAggregationsEqual(t, sumA, sumB) | |
AssertAggregationsEqual(t, gaugeA, gaugeB) | |
AssertAggregationsEqual(t, histogramA, histogramB) | |
} | |
func TestFailAssertValuesEqual(t *testing.T) { | |
AssertValuesEqual(t, int64A, nil) | |
AssertValuesEqual(t, int64A, float64A) | |
AssertValuesEqual(t, unknownValue{}, unknownValue{}) | |
AssertValuesEqual(t, int64A, int64B) | |
AssertValuesEqual(t, float64A, float64B) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go test -tags tests_fail ./... | |
--- FAIL: TestFailAssertEqual (0.00s) | |
--- FAIL: TestFailAssertEqual/ResourceMetrics (0.00s) | |
assertion_fail_test.go:26: Resources not equal: | |
expected: resource=A | |
actual: resource=B | |
ResourceMetrics ScopeMetrics not equal: | |
missing expected values: | |
metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"A", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"A", Description:"A desc", Unit:"1", Data:metricdata.Sum{DataPoints:[]metricdata.DataPoint{metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1}}, Temporality:0x1, IsMonotonic:true}}}} | |
unexpected additional values: | |
metricdata.ScopeMetrics{Scope:instrumentation.Scope{Name:"B", Version:"", SchemaURL:""}, Metrics:[]metricdata.Metrics{metricdata.Metrics{Name:"B", Description:"B desc", Unit:"By", Data:metricdata.Gauge{DataPoints:[]metricdata.DataPoint{metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2}}}}}} | |
--- FAIL: TestFailAssertEqual/ScopeMetrics (0.00s) | |
assertion_fail_test.go:26: Scope not equal: | |
expected: {A } | |
actual: {B } | |
ScopeMetrics Metrics not equal: | |
missing expected values: | |
metricdata.Metrics{Name:"A", Description:"A desc", Unit:"1", Data:metricdata.Sum{DataPoints:[]metricdata.DataPoint{metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1}}, Temporality:0x1, IsMonotonic:true}} | |
unexpected additional values: | |
metricdata.Metrics{Name:"B", Description:"B desc", Unit:"By", Data:metricdata.Gauge{DataPoints:[]metricdata.DataPoint{metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2}}}} | |
--- FAIL: TestFailAssertEqual/Metrics (0.00s) | |
assertion_fail_test.go:26: Name not equal: | |
expected: A | |
actual: B | |
Description not equal: | |
expected: A desc | |
actual: B desc | |
Unit not equal: | |
expected: 1 | |
actual: By | |
Metrics Data not equal: | |
Aggregation types not equal: | |
expected: metricdata.Sum | |
actual: metricdata.Gauge | |
--- FAIL: TestFailAssertEqual/Histogram (0.00s) | |
assertion_fail_test.go:26: Temporality not equal: | |
expected: 1 | |
actual: 2 | |
Histogram DataPoints not equal: | |
missing expected values: | |
metricdata.HistogramDataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Count:0x2, Bounds:[]float64{0, 10}, BucketCounts:[]uint64{0x1, 0x1}, Min:(*float64)(nil), Max:(*float64)(nil), Sum:2} | |
unexpected additional values: | |
metricdata.HistogramDataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Count:0x3, Bounds:[]float64{0, 10, 100}, BucketCounts:[]uint64{0x1, 0x1, 0x1}, Min:(*float64)(0x736438), Max:(*float64)(0x736430), Sum:3} | |
--- FAIL: TestFailAssertEqual/Sum (0.00s) | |
assertion_fail_test.go:26: Temporality not equal: | |
expected: 1 | |
actual: 2 | |
IsMonotonic not equal: | |
expected: true | |
actual: false | |
Sum DataPoints not equal: | |
missing expected values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1} | |
unexpected additional values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2} | |
--- FAIL: TestFailAssertEqual/Gauge (0.00s) | |
assertion_fail_test.go:26: Gauge DataPoints not equal: | |
missing expected values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1} | |
unexpected additional values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2} | |
--- FAIL: TestFailAssertEqual/HistogramDataPoint (0.00s) | |
assertion_fail_test.go:26: Attributes not equal: | |
expected: A=true | |
actual: B=true | |
StartTime not equal: | |
expected: 2022-07-20 13:18:07.26080295 +0000 UTC m=+0.001804724 | |
actual: 2022-07-20 13:18:07.26180295 +0000 UTC m=+0.002804724 | |
Time not equal: | |
expected: 2022-07-20 13:18:08.26080295 +0000 UTC m=+1.001804724 | |
actual: 2022-07-20 13:18:08.26180295 +0000 UTC m=+1.002804724 | |
Count not equal: | |
expected: 2 | |
actual: 3 | |
Bounds not equal: | |
expected: [0 10] | |
actual: [0 10 100] | |
BucketCounts not equal: | |
expected: [1 1] | |
actual: [1 1 1] | |
Min not equal: | |
expected: <nil> | |
actual: 0x736438 | |
Max not equal: | |
expected: <nil> | |
actual: 0x736430 | |
Sum not equal: | |
expected: 2 | |
actual: 3 | |
--- FAIL: TestFailAssertEqual/DataPoint (0.00s) | |
assertion_fail_test.go:26: Attributes not equal: | |
expected: A=true | |
actual: B=true | |
StartTime not equal: | |
expected: 2022-07-20 13:18:07.26080295 +0000 UTC m=+0.001804724 | |
actual: 2022-07-20 13:18:07.26180295 +0000 UTC m=+0.002804724 | |
Time not equal: | |
expected: 2022-07-20 13:18:08.26080295 +0000 UTC m=+1.001804724 | |
actual: 2022-07-20 13:18:08.26180295 +0000 UTC m=+1.002804724 | |
DataPoint Value not equal: | |
Value types not equal: | |
expected: metricdata.Int64 | |
actual: metricdata.Float64 | |
--- FAIL: TestFailAssertEqual/Int64 (0.00s) | |
assertion_fail_test.go:26: Int64 value not equal: | |
expected: -1 | |
actual: 2 | |
--- FAIL: TestFailAssertEqual/Float64 (0.00s) | |
assertion_fail_test.go:26: Float64 value not equal: | |
expected: -1 | |
actual: 2 | |
--- FAIL: TestFailAssertAggregationsEqual (0.00s) | |
assertion_fail_test.go:44: Aggregation not equal: | |
expected: {[{{{[{A {1 1 <nil>}}]}} 2022-07-20 13:18:07.26080295 +0000 UTC m=+0.001804724 2022-07-20 13:18:08.26080295 +0000 UTC m=+1.001804724 -1}] 1 true} | |
actual: <nil> | |
assertion_fail_test.go:45: Aggregation types not equal: | |
expected: metricdata.Sum | |
actual: metricdata.Gauge | |
assertion_fail_test.go:46: Aggregation of unknown types metricdatatest.unknownAggregation | |
assertion_fail_test.go:47: Sum not equal: | |
Temporality not equal: | |
expected: 1 | |
actual: 2 | |
IsMonotonic not equal: | |
expected: true | |
actual: false | |
Sum DataPoints not equal: | |
missing expected values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1} | |
unexpected additional values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2} | |
assertion_fail_test.go:48: Gauge not equal: | |
Gauge DataPoints not equal: | |
missing expected values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Value:-1} | |
unexpected additional values: | |
metricdata.DataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Value:2} | |
assertion_fail_test.go:49: Histogram not equal: | |
Temporality not equal: | |
expected: 1 | |
actual: 2 | |
Histogram DataPoints not equal: | |
missing expected values: | |
metricdata.HistogramDataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"A", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 260802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 260802950, time.Local), Count:0x2, Bounds:[]float64{0, 10}, BucketCounts:[]uint64{0x1, 0x1}, Min:(*float64)(nil), Max:(*float64)(nil), Sum:2} | |
unexpected additional values: | |
metricdata.HistogramDataPoint{Attributes:attribute.Set{equivalent:attribute.Distinct{iface:[1]attribute.KeyValue{attribute.KeyValue{Key:"B", Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}}}, StartTime:time.Date(2022, time.July, 20, 13, 18, 7, 261802950, time.Local), Time:time.Date(2022, time.July, 20, 13, 18, 8, 261802950, time.Local), Count:0x3, Bounds:[]float64{0, 10, 100}, BucketCounts:[]uint64{0x1, 0x1, 0x1}, Min:(*float64)(0x736438), Max:(*float64)(0x736430), Sum:3} | |
--- FAIL: TestFailAssertValuesEqual (0.00s) | |
assertion_fail_test.go:53: Values not equal: | |
expected: -1 | |
actual: <nil> | |
assertion_fail_test.go:54: Value types not equal: | |
expected: metricdata.Int64 | |
actual: metricdata.Float64 | |
assertion_fail_test.go:55: Value of unknown types metricdatatest.unknownValue | |
assertion_fail_test.go:56: Int64 not equal: | |
Int64 value not equal: | |
expected: -1 | |
actual: 2 | |
assertion_fail_test.go:57: Int64 not equal: | |
Float64 value not equal: | |
expected: -1 | |
actual: 2 | |
FAIL | |
FAIL go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest 0.008s | |
FAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment