44package otlptext
55
66import (
7+ "fmt"
78 "os"
89 "path/filepath"
910 "strings"
@@ -12,6 +13,7 @@ import (
1213 "github.com/stretchr/testify/assert"
1314 "github.com/stretchr/testify/require"
1415
16+ "go.opentelemetry.io/collector/pdata/pcommon"
1517 "go.opentelemetry.io/collector/pdata/pprofile"
1618 "go.opentelemetry.io/collector/pdata/testdata"
1719)
@@ -50,6 +52,55 @@ func TestProfilesText(t *testing.T) {
5052 }
5153}
5254
55+ func TestProfilesTextSampleAttributeValues (t * testing.T ) {
56+ tests := []struct {
57+ name string
58+ setValue func (pcommon.Value )
59+ expected string
60+ }{
61+ {name : "empty" , setValue : func (v pcommon.Value ) {}, expected : "<nil>" },
62+ {name : "string" , setValue : func (v pcommon.Value ) { v .SetStr ("value" ) }, expected : "value" },
63+ {name : "integer" , setValue : func (v pcommon.Value ) { v .SetInt (42 ) }, expected : "42" },
64+ {name : "double" , setValue : func (v pcommon.Value ) { v .SetDouble (3.14 ) }, expected : "3.14" },
65+ {name : "boolean" , setValue : func (v pcommon.Value ) { v .SetBool (true ) }, expected : "true" },
66+ {
67+ name : "bytes" ,
68+ setValue : func (v pcommon.Value ) { v .SetEmptyBytes ().FromRaw ([]byte {1 , 2 , 3 }) },
69+ expected : "[1 2 3]" ,
70+ },
71+ {
72+ name : "map" ,
73+ setValue : func (v pcommon.Value ) { _ = v .SetEmptyMap ().FromRaw (map [string ]any {"nested" : "value" }) },
74+ expected : "map[nested:value]" ,
75+ },
76+ {
77+ name : "slice" ,
78+ setValue : func (v pcommon.Value ) { _ = v .SetEmptySlice ().FromRaw ([]any {"value" , true }) },
79+ expected : "[value true]" ,
80+ },
81+ }
82+
83+ for _ , tt := range tests {
84+ t .Run (tt .name , func (t * testing.T ) {
85+ profiles := pprofile .NewProfiles ()
86+ dic := profiles .Dictionary ()
87+ dic .StringTable ().Append ("" )
88+ dic .StringTable ().Append ("key" )
89+ attribute := dic .AttributeTable ().AppendEmpty ()
90+ attribute .SetKeyStrindex (1 )
91+ tt .setValue (attribute .Value ())
92+
93+ sample := profiles .ResourceProfiles ().AppendEmpty ().ScopeProfiles ().AppendEmpty ().Profiles ().AppendEmpty ().Samples ().AppendEmpty ()
94+ sample .Values ().Append (100 )
95+ sample .AttributeIndices ().Append (0 )
96+
97+ output , err := NewTextProfilesMarshaler ().MarshalProfiles (profiles )
98+ require .NoError (t , err )
99+ assert .Contains (t , string (output ), fmt .Sprintf ("-> key: %s" , tt .expected ))
100+ })
101+ }
102+ }
103+
53104func TestProfilesTextInvalidDictionaryIndex (t * testing.T ) {
54105 tests := []struct {
55106 name string
0 commit comments