1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-30 08:06:40 +02:00
go-micro/metadata/metadata_test.go

43 lines
709 B
Go
Raw Normal View History

2016-03-14 20:32:08 +02:00
package metadata
import (
2018-03-03 13:53:52 +02:00
"context"
2016-03-14 20:32:08 +02:00
"testing"
)
2019-01-17 11:40:49 +02:00
func TestMetadataCopy(t *testing.T) {
md := Metadata{
"foo": "bar",
"bar": "baz",
}
cp := Copy(md)
for k, v := range md {
if cv := cp[k]; cv != v {
t.Fatalf("Got %s:%s for %s:%s", k, cv, k, v)
}
}
}
2016-03-14 20:32:08 +02:00
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)
}
}