@@ -477,3 +477,40 @@ func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer tra
477477 require .Containsf (t , sd .Attributes (), attribute.KeyValue {Key : internal .ItemsFailed , Value : attribute .Int64Value (failedToSendSpans )}, "SpanData %v" , sd )
478478 }
479479}
480+
481+ func TestSerializableToLink (t * testing.T ) {
482+ sl := SerializableLink {
483+ TraceID : [16 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 },
484+ SpanID : [8 ]byte {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 },
485+ TraceFlags : byte (trace .FlagsSampled ),
486+ TraceState : TraceStateSerializable {
487+ Members : []struct {
488+ Key string `json:"key"`
489+ Value string `json:"value"`
490+ }{
491+ {
492+ Key : "@key" , // @ is not allowed in trace state keys
493+ Value : "value" ,
494+ },
495+ },
496+ },
497+ }
498+ res := serializableToLink (sl )
499+ // TraceState will be empty due to error in inserting Member Key "@key"
500+ assert .Equal (t , trace.TraceState {}, res .SpanContext .TraceState ())
501+ }
502+
503+ func TestTracesEncoding_Unmarshal_InvalidJSON (t * testing.T ) {
504+ // Create invalid JSON bytes
505+ invalidJSON := []byte (`{invalid json}` )
506+
507+ // Create tracesEncoding instance
508+ encoding := tracesEncoding {}
509+
510+ // Attempt to unmarshal invalid JSON
511+ req , err := encoding .Unmarshal (invalidJSON )
512+
513+ // Verify error is returned and request is nil
514+ require .Error (t , err )
515+ assert .Nil (t , req )
516+ }
0 commit comments