| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package tracetransform |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
|
| 11 |
"go.opentelemetry.io/otel/attribute" |
| 12 |
"go.opentelemetry.io/otel/sdk/resource" |
| 13 |
) |
| 14 |
|
| 15 |
func TestNilResource(t *testing.T) { |
| 16 |
assert.Empty(t, Resource(nil)) |
| 17 |
} |
| 18 |
|
| 19 |
func TestEmptyResource(t *testing.T) { |
| 20 |
assert.Empty(t, Resource(&resource.Resource{})) |
| 21 |
} |
| 22 |
|
| 23 |
/* |
| 24 |
* This does not include any testing on the ordering of Resource Attributes. |
| 25 |
* They are stored as a map internally to the Resource and their order is not |
| 26 |
* guaranteed. |
| 27 |
*/ |
| 28 |
|
| 29 |
func TestResourceAttributes(t *testing.T) { |
| 30 |
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} |
| 31 |
|
| 32 |
got := Resource(resource.NewSchemaless(attrs...)).GetAttributes() |
| 33 |
if !assert.Len(t, attrs, 2) { |
| 34 |
return |
| 35 |
} |
| 36 |
assert.ElementsMatch(t, KeyValues(attrs), got) |
| 37 |
} |