Skip to content

Commit

Permalink
Add test for textMapAdapter.Keys
Browse files Browse the repository at this point in the history
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 <bjboreham@gmail.com>
  • Loading branch information
bboreham committed Apr 18, 2022
1 parent fcb9b2a commit 344c66b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bridge/opentracing/bridge_test.go
Expand Up @@ -16,6 +16,7 @@ package opentracing

import (
"reflect"
"sort"
"testing"

ot "github.com/opentracing/opentracing-go"
Expand All @@ -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)
Expand Down

0 comments on commit 344c66b

Please sign in to comment.