1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-14 10:13:10 +02:00
opentelemetry-go/exporters/otlp/internal/transform/attribute_test.go
Tyler Yahn 7d631dbfaa
Upgrade OTLP exporter to opentelemetry-proto matching the opentelemetry-collector v0.4.0 release (#866)
* Update OTLP to v0.4.0

* Update attribute transforms to use new KeyValue

* Update metric transforms

The labels are no longer included in the MetricDescriptor

Use new types.

* Fix OTLP integration tests

* Update example otel-collector go.sum

* Update metric integration testing

* Fix type error introduced in conflict resolution

* Deep clean of go.sum

Recreate go.sum for otel-collector example and OTLP exporter.
2020-06-24 14:02:13 -07:00

149 lines
3.5 KiB
Go

// 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.
package transform
import (
"testing"
commonpb "github.com/open-telemetry/opentelemetry-proto/gen/go/common/v1"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/api/kv"
)
func TestAttributes(t *testing.T) {
for _, test := range []struct {
attrs []kv.KeyValue
expected []*commonpb.KeyValue
}{
{nil, nil},
{
[]kv.KeyValue{
kv.Int("int to int", 123),
kv.Uint("uint to int", 1234),
kv.Int32("int32 to int", 12345),
kv.Uint32("uint32 to int", 123456),
kv.Int64("int64 to int64", 1234567),
kv.Uint64("uint64 to int64", 12345678),
kv.Float32("float32 to double", 3.14),
kv.Float32("float64 to double", 1.61),
kv.String("string to string", "string"),
kv.Bool("bool to bool", true),
},
[]*commonpb.KeyValue{
{
Key: "int to int",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 123,
},
},
},
{
Key: "uint to int",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 1234,
},
},
},
{
Key: "int32 to int",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 12345,
},
},
},
{
Key: "uint32 to int",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 123456,
},
},
},
{
Key: "int64 to int64",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 1234567,
},
},
},
{
Key: "uint64 to int64",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_IntValue{
IntValue: 12345678,
},
},
},
{
Key: "float32 to double",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_DoubleValue{
DoubleValue: 3.14,
},
},
},
{
Key: "float64 to double",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_DoubleValue{
DoubleValue: 1.61,
},
},
},
{
Key: "string to string",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_StringValue{
StringValue: "string",
},
},
},
{
Key: "bool to bool",
Value: &commonpb.AnyValue{
Value: &commonpb.AnyValue_BoolValue{
BoolValue: true,
},
},
},
},
},
} {
got := Attributes(test.attrs)
if !assert.Len(t, got, len(test.expected)) {
continue
}
for i, actual := range got {
if a, ok := actual.Value.Value.(*commonpb.AnyValue_DoubleValue); ok {
e, ok := test.expected[i].Value.Value.(*commonpb.AnyValue_DoubleValue)
if !ok {
t.Errorf("expected AnyValue_DoubleValue, got %T", test.expected[i].Value.Value)
continue
}
if !assert.InDelta(t, e.DoubleValue, a.DoubleValue, 0.01) {
continue
}
e.DoubleValue = a.DoubleValue
}
assert.Equal(t, test.expected[i], actual)
}
}
}