micro/metadata/metadata_test.go

28 lines
491 B
Go
Raw Normal View History

2016-03-14 21:32:08 +03:00
package metadata
import (
2018-03-03 14:53:52 +03:00
"context"
2016-03-14 21:32:08 +03:00
"testing"
)
func TestMetadataContext(t *testing.T) {
md := Metadata{
"foo": "bar",
}
ctx := NewContext(context.TODO(), md)
emd, ok := FromContext(ctx)
if !ok {
t.Errorf("Unexpected error retrieving metadata, got %t", ok)
}
if emd["foo"] != md["foo"] {
t.Errorf("Expected key: %s val: %s, got key: %s val: %s", "foo", md["foo"], "foo", emd["foo"])
}
if i := len(emd); i != 1 {
t.Errorf("Expected metadata length 1 got %d", i)
}
}