go.undefinedlabs.com/scopeagent@v0.4.2/tracer/wire/carrier_test.go (about) 1 package wire_test 2 3 import ( 4 "testing" 5 6 "github.com/opentracing/basictracer-go" 7 "github.com/opentracing/basictracer-go/wire" 8 ) 9 10 func TestProtobufCarrier(t *testing.T) { 11 var carrier basictracer.DelegatingCarrier = &wire.ProtobufCarrier{} 12 13 var traceID, spanID uint64 = 1, 2 14 sampled := true 15 baggageKey, expVal := "key1", "val1" 16 17 carrier.SetState(traceID, spanID, sampled) 18 carrier.SetBaggageItem(baggageKey, expVal) 19 gotTraceID, gotSpanID, gotSampled := carrier.State() 20 if traceID != gotTraceID || spanID != gotSpanID || sampled != gotSampled { 21 t.Errorf("Wanted state %d %d %t, got %d %d %t", spanID, traceID, sampled, 22 gotTraceID, gotSpanID, gotSampled) 23 } 24 25 gotBaggage := map[string]string{} 26 f := func(k, v string) { 27 gotBaggage[k] = v 28 } 29 30 carrier.GetBaggage(f) 31 value, ok := gotBaggage[baggageKey] 32 if !ok { 33 t.Errorf("Expected baggage item %s to exist", baggageKey) 34 } 35 if value != expVal { 36 t.Errorf("Expected key %s to be %s, got %s", baggageKey, expVal, value) 37 } 38 }