| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
//go:build tests_fail |
| 5 |
|
| 6 |
package metricdatatest // import "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" |
| 7 |
|
| 8 |
import ( |
| 9 |
"testing" |
| 10 |
|
| 11 |
"go.opentelemetry.io/otel/attribute" |
| 12 |
) |
| 13 |
|
| 14 |
// These tests are used to develop the failure messages of this package's |
| 15 |
// assertions. They can be run with the following. |
| 16 |
// |
| 17 |
// go test -tags tests_fail ./... |
| 18 |
|
| 19 |
func testFailDatatype[T Datatypes](a, b T) func(*testing.T) { |
| 20 |
return func(t *testing.T) { |
| 21 |
AssertEqual(t, a, b) |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
func TestFailAssertEqual(t *testing.T) { |
| 26 |
t.Run("ResourceMetrics", testFailDatatype(resourceMetricsA, resourceMetricsB)) |
| 27 |
t.Run("ScopeMetrics", testFailDatatype(scopeMetricsA, scopeMetricsB)) |
| 28 |
t.Run("Metrics", testFailDatatype(metricsA, metricsB)) |
| 29 |
t.Run("HistogramInt64", testFailDatatype(histogramInt64A, histogramInt64B)) |
| 30 |
t.Run("HistogramFloat64", testFailDatatype(histogramFloat64A, histogramFloat64B)) |
| 31 |
t.Run("SumInt64", testFailDatatype(sumInt64A, sumInt64B)) |
| 32 |
t.Run("SumFloat64", testFailDatatype(sumFloat64A, sumFloat64B)) |
| 33 |
t.Run("GaugeInt64", testFailDatatype(gaugeInt64A, gaugeInt64B)) |
| 34 |
t.Run("GaugeFloat64", testFailDatatype(gaugeFloat64A, gaugeFloat64B)) |
| 35 |
t.Run("HistogramDataPointInt64", testFailDatatype(histogramDataPointInt64A, histogramDataPointInt64B)) |
| 36 |
t.Run("HistogramDataPointFloat64", testFailDatatype(histogramDataPointFloat64A, histogramDataPointFloat64B)) |
| 37 |
t.Run("DataPointInt64", testFailDatatype(dataPointInt64A, dataPointInt64B)) |
| 38 |
t.Run("DataPointFloat64", testFailDatatype(dataPointFloat64A, dataPointFloat64B)) |
| 39 |
t.Run("ExemplarInt64", testFailDatatype(exemplarInt64A, exemplarInt64B)) |
| 40 |
t.Run("ExemplarFloat64", testFailDatatype(exemplarFloat64A, exemplarFloat64B)) |
| 41 |
t.Run("Extrema", testFailDatatype(minA, minB)) |
| 42 |
} |
| 43 |
|
| 44 |
func TestFailAssertAggregationsEqual(t *testing.T) { |
| 45 |
AssertAggregationsEqual(t, sumInt64A, nil) |
| 46 |
AssertAggregationsEqual(t, sumFloat64A, gaugeFloat64A) |
| 47 |
AssertAggregationsEqual(t, unknownAggregation{}, unknownAggregation{}) |
| 48 |
AssertAggregationsEqual(t, sumInt64A, sumInt64B) |
| 49 |
AssertAggregationsEqual(t, sumFloat64A, sumFloat64B) |
| 50 |
AssertAggregationsEqual(t, gaugeInt64A, gaugeInt64B) |
| 51 |
AssertAggregationsEqual(t, gaugeFloat64A, gaugeFloat64B) |
| 52 |
AssertAggregationsEqual(t, histogramInt64A, histogramInt64B) |
| 53 |
AssertAggregationsEqual(t, histogramFloat64A, histogramFloat64B) |
| 54 |
} |
| 55 |
|
| 56 |
func TestFailAssertAttribute(t *testing.T) { |
| 57 |
AssertHasAttributes(t, exemplarInt64A, attribute.Bool("A", false)) |
| 58 |
AssertHasAttributes(t, exemplarFloat64A, attribute.Bool("B", true)) |
| 59 |
AssertHasAttributes(t, dataPointInt64A, attribute.Bool("A", false)) |
| 60 |
AssertHasAttributes(t, dataPointFloat64A, attribute.Bool("B", true)) |
| 61 |
AssertHasAttributes(t, gaugeInt64A, attribute.Bool("A", false)) |
| 62 |
AssertHasAttributes(t, gaugeFloat64A, attribute.Bool("B", true)) |
| 63 |
AssertHasAttributes(t, sumInt64A, attribute.Bool("A", false)) |
| 64 |
AssertHasAttributes(t, sumFloat64A, attribute.Bool("B", true)) |
| 65 |
AssertHasAttributes(t, histogramDataPointInt64A, attribute.Bool("A", false)) |
| 66 |
AssertHasAttributes(t, histogramDataPointFloat64A, attribute.Bool("B", true)) |
| 67 |
AssertHasAttributes(t, histogramInt64A, attribute.Bool("A", false)) |
| 68 |
AssertHasAttributes(t, histogramFloat64A, attribute.Bool("B", true)) |
| 69 |
AssertHasAttributes(t, metricsA, attribute.Bool("A", false)) |
| 70 |
AssertHasAttributes(t, metricsA, attribute.Bool("B", true)) |
| 71 |
AssertHasAttributes(t, resourceMetricsA, attribute.Bool("A", false)) |
| 72 |
AssertHasAttributes(t, resourceMetricsA, attribute.Bool("B", true)) |
| 73 |
} |