From eb05fd56b31e11a31c8113a7f70fe42b38a68724 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 11 Jul 2024 08:14:57 -0700 Subject: [PATCH] Add TestConfigLinkMutability (#5604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow up to #5567. Test the immutability of configured links. Co-authored-by: Robert PajÄ…k --- trace/trace_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/trace/trace_test.go b/trace/trace_test.go index 73ee3ce49bc..8e51df33dd5 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -643,3 +643,21 @@ func TestLinkFromContext(t *testing.T) { } assert.Equal(t, link.Attributes[0], k1v1) } + +func TestConfigLinkMutability(t *testing.T) { + sc0 := NewSpanContext(SpanContextConfig{TraceID: [16]byte{1}}) + sc1 := NewSpanContext(SpanContextConfig{TraceID: [16]byte{2}}) + sc2 := NewSpanContext(SpanContextConfig{TraceID: [16]byte{3}}) + l0 := Link{SpanContext: sc0} + l1 := Link{SpanContext: sc1} + l2 := Link{SpanContext: sc2} + + links := []Link{l0, l1} + conf := NewSpanStartConfig(WithLinks(links...)) + + // Mutating passed arg should not change configured links. + links[0] = l2 + + want := SpanConfig{links: []Link{l0, l1}} + assert.Equal(t, want, conf) +}