Skip to content

Commit 9f9cc84

Browse files
test: add tests for traces marshaler
1 parent 45feb7a commit 9f9cc84

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
"go.opentelemetry.io/collector/pdata/ptrace"
11+
)
12+
13+
func TestMarshalTraces(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
input ptrace.Traces
17+
expected string
18+
}{
19+
{
20+
name: "empty traces",
21+
input: ptrace.NewTraces(),
22+
expected: "",
23+
},
24+
{
25+
name: "one span",
26+
input: func() ptrace.Traces {
27+
traces := ptrace.NewTraces()
28+
span := traces.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
29+
span.SetName("span-name")
30+
span.SetTraceID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
31+
span.SetSpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18})
32+
return traces
33+
}(),
34+
expected: `span-name 0102030405060708090a0b0c0d0e0f10 1112131415161718
35+
`,
36+
},
37+
}
38+
for _, tt := range tests {
39+
t.Run(tt.name, func(t *testing.T) {
40+
output, err := NewNormalTracesMarshaler().MarshalTraces(tt.input)
41+
assert.NoError(t, err)
42+
assert.Equal(t, tt.expected, string(output))
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)