2020-03-24 07:41:10 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-10-17 07:49:58 +02:00
|
|
|
package key_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
2019-11-01 20:40:29 +02:00
|
|
|
"go.opentelemetry.io/otel/api/core"
|
|
|
|
"go.opentelemetry.io/otel/api/key"
|
2019-10-17 07:49:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestKeyValueConstructors(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
actual core.KeyValue
|
|
|
|
expected core.KeyValue
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Bool",
|
|
|
|
actual: key.Bool("k1", true),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Bool(true),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Int64",
|
|
|
|
actual: key.Int64("k1", 123),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Int64(123),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Uint64",
|
|
|
|
actual: key.Uint64("k1", 1),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Uint64(1),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Float64",
|
|
|
|
actual: key.Float64("k1", 123.5),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Float64(123.5),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Int32",
|
|
|
|
actual: key.Int32("k1", 123),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Int32(123),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Uint32",
|
|
|
|
actual: key.Uint32("k1", 123),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Uint32(123),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Float32",
|
|
|
|
actual: key.Float32("k1", 123.5),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Float32(123.5),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-31 18:31:46 +02:00
|
|
|
{
|
|
|
|
name: "String",
|
|
|
|
actual: key.String("k1", "123.5"),
|
|
|
|
expected: core.KeyValue{
|
|
|
|
Key: "k1",
|
|
|
|
Value: core.String("123.5"),
|
|
|
|
},
|
|
|
|
},
|
2019-10-17 07:49:58 +02:00
|
|
|
{
|
|
|
|
name: "Int",
|
|
|
|
actual: key.Int("k1", 123),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Int(123),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Uint",
|
|
|
|
actual: key.Uint("k1", 123),
|
|
|
|
expected: core.KeyValue{
|
2019-10-31 00:01:19 +02:00
|
|
|
Key: "k1",
|
|
|
|
Value: core.Uint(123),
|
2019-10-17 07:49:58 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tt {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2019-10-31 00:01:19 +02:00
|
|
|
if diff := cmp.Diff(test.actual, test.expected, cmp.AllowUnexported(core.Value{})); diff != "" {
|
2019-10-17 07:49:58 +02:00
|
|
|
t.Fatal(diff)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|