-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathidentity_test.go
More file actions
67 lines (61 loc) · 1.75 KB
/
Copy pathidentity_test.go
File metadata and controls
67 lines (61 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package tracing
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewIdentity(t *testing.T) {
testCases := []struct {
testCase string
trace string
expected string
}{
{
testCase: "full length trace",
trace: "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
expected: "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
},
{
testCase: "short trace ID",
trace: "ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
expected: "0000ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
},
{
testCase: "short trace ID with 0s in the middle",
trace: "ad8a01fde11f000002efdce36873:52726f6cabc144f5:0:1",
expected: "0000ad8a01fde11f000002efdce36873:52726f6cabc144f5:0:1",
},
{
testCase: "short trace ID with 0s in the beginning and middle",
trace: "001ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
expected: "0001ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1",
},
{
testCase: "no trace",
trace: "",
},
{
testCase: "missing flags",
trace: "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0",
},
{
testCase: "missing separator",
trace: "ec31ad8a01fde11fdcabe2efdce3687352726f6cabc144f501",
},
}
for _, testCase := range testCases {
identity, err := NewIdentity(testCase.trace)
if testCase.expected != "" {
require.NoError(t, err)
require.Equal(t, testCase.expected, identity.String())
serializedIdentity, err := identity.MarshalBinary()
require.NoError(t, err)
deserializedIdentity := new(Identity)
err = deserializedIdentity.UnmarshalBinary(serializedIdentity)
require.NoError(t, err)
require.Equal(t, identity, deserializedIdentity)
} else {
require.Error(t, err)
require.Nil(t, identity)
}
}
}