| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pcommon |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestSpanID(t *testing.T) { |
| 13 |
sid := SpanID([8]byte{1, 2, 3, 4, 4, 3, 2, 1}) |
| 14 |
assert.Equal(t, [8]byte{1, 2, 3, 4, 4, 3, 2, 1}, [8]byte(sid)) |
| 15 |
assert.False(t, sid.IsEmpty()) |
| 16 |
} |
| 17 |
|
| 18 |
func TestNewSpanIDEmpty(t *testing.T) { |
| 19 |
sid := NewSpanIDEmpty() |
| 20 |
assert.Equal(t, [8]byte{}, [8]byte(sid)) |
| 21 |
assert.True(t, sid.IsEmpty()) |
| 22 |
} |
| 23 |
|
| 24 |
func TestSpanIDString(t *testing.T) { |
| 25 |
sid := SpanID([8]byte{}) |
| 26 |
assert.Empty(t, sid.String()) |
| 27 |
|
| 28 |
sid = SpanID([8]byte{0x12, 0x23, 0xAD, 0x12, 0x23, 0xAD, 0x12, 0x23}) |
| 29 |
assert.Equal(t, "1223ad1223ad1223", sid.String()) |
| 30 |
} |
| 31 |
|
| 32 |
func TestSpanIDImmutable(t *testing.T) { |
| 33 |
initialBytes := [8]byte{0x12, 0x23, 0xAD, 0x12, 0x23, 0xAD, 0x12, 0x23} |
| 34 |
sid := SpanID(initialBytes) |
| 35 |
assert.Equal(t, SpanID(initialBytes), sid) |
| 36 |
|
| 37 |
// Get the bytes and try to mutate. |
| 38 |
sid[4] = 0x89 |
| 39 |
|
| 40 |
// Does not change the already created SpanID. |
| 41 |
assert.NotEqual(t, SpanID(initialBytes), sid) |
| 42 |
} |