Debian Codegraph @

zpages/templates_test.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package zpages
5
6 import (
7 "html/template"
8 "testing"
9
10 "github.com/stretchr/testify/assert"
11 "go.opentelemetry.io/otel/trace"
12 )
13
14 func TestSpanRowFormatter(t *testing.T) {
15 for _, tt := range []struct {
16 name string
17 row spanRow
18
19 expectedTemplate template.HTML
20 }{
21 {
22 name: "with an invalid span context",
23 row: spanRow{
24 SpanContext: trace.NewSpanContext(trace.SpanContextConfig{}),
25 },
26 expectedTemplate: "",
27 },
28 {
29 name: "with a valid span context",
30 row: spanRow{
31 SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
32 TraceID: trace.TraceID{2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9},
33 SpanID: trace.SpanID{1, 2, 3, 4, 5, 6, 7, 8},
34 }),
35 },
36 expectedTemplate: "trace_id: <b style=\"color:black\">02030405060708090203040506070809</b> span_id: 0102030405060708",
37 },
38 {
39 name: "with a valid parent span context",
40 row: spanRow{
41 SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
42 TraceID: trace.TraceID{2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 6, 7, 8, 9},
43 SpanID: trace.SpanID{1, 2, 3, 4, 5, 6, 7, 8},
44 }),
45 ParentSpanContext: trace.NewSpanContext(trace.SpanContextConfig{
46 TraceID: trace.TraceID{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25},
47 SpanID: trace.SpanID{10, 11, 12, 13, 14, 15, 16, 18},
48 }),
49 },
50 expectedTemplate: "trace_id: <b style=\"color:black\">02030405060708090203040506070809</b> span_id: 0102030405060708 parent_span_id: 0a0b0c0d0e0f1012",
51 },
52 } {
53 t.Run(tt.name, func(t *testing.T) {
54 r := spanRowFormatter(tt.row)
55 assert.Equal(t, tt.expectedTemplate, r)
56 })
57 }
58 }