Skip to content

Commit

Permalink
Update Unit Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Dec 17, 2024
1 parent 910520c commit 19db667
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions cmd/query/app/querysvc/adjuster/spanlinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/jaegertracing/jaeger/internal/jptrace"
)

func TestLinksAdjuster(t *testing.T) {
Expand All @@ -21,19 +23,32 @@ func TestLinksAdjuster(t *testing.T) {
scopeSpans.Spans().AppendEmpty()

// span with empty traceID link
spanA := scopeSpans.Spans().AppendEmpty()
spanA.Links().AppendEmpty().SetTraceID(pcommon.NewTraceIDEmpty())
spanB := scopeSpans.Spans().AppendEmpty()
spanB.Links().AppendEmpty().SetTraceID(pcommon.NewTraceIDEmpty())

// span with 2 non-empty traceID links and 1 empty (or zero) traceID link
spanB := scopeSpans.Spans().AppendEmpty()
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}))
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}))
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))
spanC := scopeSpans.Spans().AppendEmpty()
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}))
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}))
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))

err := SpanLinks().Adjust(traces)
spans := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans()
require.NoError(t, err)
assert.Equal(t, 0, spans.At(0).Links().Len())
assert.Equal(t, 0, spans.At(1).Links().Len())
assert.Equal(t, 2, spans.At(2).Links().Len())

gotSpansA := spans.At(0)
assert.Equal(t, 0, gotSpansA.Links().Len())
assert.Empty(t, jptrace.GetWarnings(gotSpansA))

gotSpansB := spans.At(1)
assert.Equal(t, 0, gotSpansB.Links().Len())
spanBWarnings := jptrace.GetWarnings(gotSpansB)
assert.Len(t, spanBWarnings, 1)
assert.Equal(t, "Invalid span link removed", spanBWarnings[0])

gotSpansC := spans.At(2)
assert.Equal(t, 2, gotSpansC.Links().Len())
spanCWarnings := jptrace.GetWarnings(gotSpansC)
assert.Len(t, spanCWarnings, 1)
assert.Equal(t, "Invalid span link removed", spanCWarnings[0])
}

0 comments on commit 19db667

Please sign in to comment.