Files
telemetry/pdata/xpdata/entity/resource_entities_test.go
Dmitry AnoshinandGitHub 8038c69493 [xpdata] Add high-level API for managing entities attached to resources (#14039)
Introduce `Entity`, `EntitySlice`, and `EntityAttributeMap` types that
provide a user-friendly interface for working with resource entities.
The new API ensures consistency between entity and resource attributes
by sharing the underlying attribute map, and prevents attribute
conflicts between entities. This API should eventually replace the
generated protobuf-based API for better usability.

Resolves
https://github.com/open-telemetry/opentelemetry-collector/issues/14042
2025-10-23 20:58:30 +00:00

39 lines
843 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package entity
import (
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
)
func TestResourceEntityRefs(t *testing.T) {
res := pcommon.NewResource()
refs := ResourceEntityRefs(res)
assert.Equal(t, 0, refs.Len())
ref := refs.AppendEmpty()
ref.SetType("service")
assert.Equal(t, 1, refs.Len())
assert.Equal(t, "service", refs.At(0).Type())
}
func TestResourceEntities(t *testing.T) {
res := pcommon.NewResource()
entities := ResourceEntities(res)
assert.Equal(t, 0, entities.Len())
e := entities.PutEmpty("service")
assert.Equal(t, 1, entities.Len())
retrieved, ok := entities.Get("service")
assert.True(t, ok)
assert.Equal(t, "service", retrieved.Type())
assert.Equal(t, "service", e.Type())
}