Debian Codegraph @

exporter/debugexporter/internal/normal/profiles_test.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package normal
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11
12 "go.opentelemetry.io/collector/pdata/pprofile"
13 )
14
15 func TestMarshalProfiles(t *testing.T) {
16 tests := []struct {
17 name string
18 input pprofile.Profiles
19 expected string
20 }{
21 {
22 name: "empty profile",
23 input: pprofile.NewProfiles(),
24 expected: "",
25 },
26 {
27 name: "one profile",
28 input: func() pprofile.Profiles {
29 profiles := pprofile.NewProfiles()
30 dic := profiles.Dictionary()
31 dic.StringTable().Append("")
32 dic.StringTable().Append("key1")
33
34 a := dic.AttributeTable().AppendEmpty()
35 a.SetKeyStrindex(1)
36 a.Value().SetStr("value1")
37
38 profile := profiles.ResourceProfiles().AppendEmpty().ScopeProfiles().AppendEmpty().Profiles().AppendEmpty()
39 profiles.ResourceProfiles().At(0).SetSchemaUrl("https://example.com/resource")
40 profiles.ResourceProfiles().At(0).Resource().Attributes().PutStr("resourceKey", "resourceValue")
41 profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).SetSchemaUrl("https://example.com/scope")
42 profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().SetName("scope-name")
43 profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().SetVersion("1.2.3")
44 profiles.ResourceProfiles().At(0).ScopeProfiles().At(0).Scope().Attributes().PutStr("scopeKey", "scopeValue")
45 profile.SetProfileID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
46 profile.Samples().AppendEmpty()
47 profile.Samples().AppendEmpty()
48 profile.AttributeIndices().Append(0)
49 return profiles
50 }(),
51 expected: `ResourceProfiles #0 [https://example.com/resource] resourceKey=resourceValue
52 ScopeProfiles #0 [email protected] [https://example.com/scope] scopeKey=scopeValue
53 0102030405060708090a0b0c0d0e0f10 samples=2 key1=value1
54 `,
55 },
56 }
57 for _, tt := range tests {
58 t.Run(tt.name, func(t *testing.T) {
59 output, err := NewNormalProfilesMarshaler().MarshalProfiles(tt.input)
60 require.NoError(t, err)
61 assert.Equal(t, tt.expected, string(output))
62 })
63 }
64 }