@@ -10,40 +10,55 @@ func TestNewIdentity(t *testing.T) {
1010 testCases := []struct {
1111 testCase string
1212 trace string
13- valid bool
13+ expected string
1414 }{
1515 {
1616 testCase : "full length trace" ,
1717 trace : "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
18- valid : true ,
18+ expected : "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
1919 },
2020 {
2121 testCase : "short trace ID" ,
2222 trace : "ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
23- valid : true ,
23+ expected : "0000ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
24+ },
25+ {
26+ testCase : "short trace ID with 0s in the middle" ,
27+ trace : "ad8a01fde11f000002efdce36873:52726f6cabc144f5:0:1" ,
28+ expected : "0000ad8a01fde11f000002efdce36873:52726f6cabc144f5:0:1" ,
29+ },
30+ {
31+ testCase : "short trace ID with 0s in the beginning and middle" ,
32+ trace : "001ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
33+ expected : "0001ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0:1" ,
2434 },
2535 {
2636 testCase : "no trace" ,
2737 trace : "" ,
28- valid : false ,
2938 },
3039 {
3140 testCase : "missing flags" ,
3241 trace : "ec31ad8a01fde11fdcabe2efdce36873:52726f6cabc144f5:0" ,
33- valid : false ,
3442 },
3543 {
3644 testCase : "missing separator" ,
3745 trace : "ec31ad8a01fde11fdcabe2efdce3687352726f6cabc144f501" ,
38- valid : false ,
3946 },
4047 }
4148
4249 for _ , testCase := range testCases {
4350 identity , err := NewIdentity (testCase .trace )
44- if testCase .valid {
45- require .NoError (t , err , testCase .testCase )
46- require .Equal (t , testCase .trace , identity .String ())
51+ if testCase .expected != "" {
52+ require .NoError (t , err )
53+ require .Equal (t , testCase .expected , identity .String ())
54+
55+ serializedIdentity , err := identity .MarshalBinary ()
56+ require .NoError (t , err )
57+ deserializedIdentity := new (Identity )
58+ err = deserializedIdentity .UnmarshalBinary (serializedIdentity )
59+ require .NoError (t , err )
60+ require .Equal (t , identity , deserializedIdentity )
61+
4762 } else {
4863 require .Error (t , err )
4964 require .Nil (t , identity )
0 commit comments