@@ -12,31 +12,18 @@ const flags = Buffer.alloc(1)
1212
1313const header = `00-${ traceId . toString ( 'hex' ) } -${ id . toString ( 'hex' ) } -00`
1414
15- test ( 'constructor' , t => {
16- const context = new TraceContext ( {
17- version,
18- traceId,
19- id,
20- flags
21- } )
22-
23- t . ok ( context instanceof TraceContext , 'has a trace context object' )
24- t . ok ( version . equals ( context . version ) , 'version matches' )
25- t . ok ( traceId . equals ( context . traceId ) , 'traceId matches' )
26- t . ok ( id . equals ( context . id ) , 'id matches' )
27- t . ok ( flags . equals ( context . flags ) , 'flags matches' )
28-
29- t . end ( )
30- } )
15+ function toHex ( buffer ) {
16+ return buffer . toString ( 'hex' )
17+ }
3118
3219test ( 'fromString' , t => {
3320 const context = TraceContext . fromString ( header )
3421
3522 t . ok ( context instanceof TraceContext , 'has a trace context object' )
36- t . ok ( version . equals ( context . version ) , 'version matches' )
37- t . ok ( traceId . equals ( context . traceId ) , 'traceId matches' )
38- t . ok ( id . equals ( context . id ) , 'id matches' )
39- t . ok ( flags . equals ( context . flags ) , 'flags matches' )
23+ t . equal ( version . toString ( 'hex' ) , context . version , 'version matches' )
24+ t . equal ( traceId . toString ( 'hex' ) , context . traceId , 'traceId matches' )
25+ t . equal ( id . toString ( 'hex' ) , context . id , 'id matches' )
26+ t . equal ( flags . toString ( 'hex' ) , context . flags , 'flags matches' )
4027
4128 t . end ( )
4229} )
@@ -55,7 +42,12 @@ test('toJSON', t => {
5542 traceId : traceId . toString ( 'hex' ) ,
5643 id : id . toString ( 'hex' ) ,
5744 flags : flags . toString ( 'hex' ) ,
58- parentId : undefined
45+ header : [
46+ version ,
47+ traceId ,
48+ id ,
49+ flags
50+ ] . map ( toHex ) . join ( '-' )
5951 } , 'trace context serializes fields to hex strings, in JSON form' )
6052
6153 t . end ( )
@@ -65,10 +57,10 @@ test('create', t => {
6557 const context = TraceContext . create ( )
6658
6759 t . ok ( context instanceof TraceContext , 'has a trace context object' )
68- t . ok ( version . equals ( context . version ) , 'version matches' )
69- t . notOk ( traceId . equals ( context . traceId ) , 'has new traceId' )
70- t . notOk ( id . equals ( context . id ) , 'has new spanId ' )
71- t . ok ( flags . equals ( context . flags ) , 'flags matches' )
60+ t . equal ( version . toString ( 'hex' ) , context . version , 'version matches' )
61+ t . notEqual ( traceId . toString ( 'hex' ) , context . traceId , 'has new traceId' )
62+ t . notEqual ( id . toString ( 'hex' ) , context . id , 'has new id ' )
63+ t . equal ( flags . toString ( 'hex' ) , context . flags , 'flags matches' )
7264
7365 t . end ( )
7466} )
@@ -78,11 +70,10 @@ test('child', t => {
7870 const context = parent . child ( )
7971
8072 t . ok ( context instanceof TraceContext , 'has a trace context object' )
81- t . ok ( version . equals ( context . version ) , 'version matches' )
82- t . ok ( traceId . equals ( context . traceId ) , 'traceId matches' )
83- t . notOk ( id . equals ( context . id ) , 'has new id' )
84- t . ok ( flags . equals ( context . flags ) , 'flags matches' )
85- t . ok ( parent . id . equals ( context . parentId ) , 'parentId matches parent.id' )
73+ t . equal ( version . toString ( 'hex' ) , context . version , 'version matches' )
74+ t . equal ( traceId . toString ( 'hex' ) , context . traceId , 'has new traceId' )
75+ t . notEqual ( id . toString ( 'hex' ) , context . id , 'has new id' )
76+ t . equal ( flags . toString ( 'hex' ) , context . flags , 'flags matches' )
8677
8778 t . end ( )
8879} )
0 commit comments