From 344c66b09a2d922605b2d2bcd4a87fa8be7d1592 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 18 Apr 2022 11:41:21 +0100 Subject: [PATCH] Add test for textMapAdapter.Keys This is not currently used in normal functioning of Inject and Extract, but might get used in future so give it some testing now. Test adapted from `open-telemetry/opentelemetry-go/propagation/propagation_test.go` Signed-off-by: Bryan Boreham --- bridge/opentracing/bridge_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bridge/opentracing/bridge_test.go b/bridge/opentracing/bridge_test.go index 4688e48a914..b74da123454 100644 --- a/bridge/opentracing/bridge_test.go +++ b/bridge/opentracing/bridge_test.go @@ -16,6 +16,7 @@ package opentracing import ( "reflect" + "sort" "testing" ot "github.com/opentracing/opentracing-go" @@ -24,6 +25,25 @@ import ( "go.opentelemetry.io/otel/propagation" ) +func TestTextMapAdapterKeys(t *testing.T) { + carrier := ot.TextMapCarrier{ + "foo": "bar", + "baz": "qux", + } + + keys := textMapAdapter{r: carrier}.Keys() + sort.Strings(keys) + expected := []string{"baz", "foo"} + if !reflect.DeepEqual(expected, keys) { + t.Errorf("Keys do not match: %#v, %#v", expected, keys) + } + // Check what happens if we read from a write-capable adaptor. + keys = textMapAdapter{w: carrier}.Keys() + if keys != nil { + t.Errorf("Keys should be nil: %#v", keys) + } +} + func TestMapCarrier(t *testing.T) { carrier := propagation.MapCarrier{} testBridgeWithCarrier(t, carrier)