1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/util/wrapper/wrapper_test.go

54 lines
961 B
Go
Raw Normal View History

package wrapper
import (
2018-03-03 13:53:52 +02:00
"context"
"testing"
"github.com/micro/go-micro/v2/metadata"
)
func TestWrapper(t *testing.T) {
testData := []struct {
existing metadata.Metadata
headers metadata.Metadata
overwrite bool
}{
{
existing: metadata.Metadata{},
headers: metadata.Metadata{
2019-12-31 15:45:49 +02:00
"Foo": "bar",
},
overwrite: true,
},
{
existing: metadata.Metadata{
2019-12-31 15:45:49 +02:00
"Foo": "bar",
},
headers: metadata.Metadata{
2019-12-31 15:45:49 +02:00
"Foo": "baz",
},
overwrite: false,
},
}
for _, d := range testData {
c := &clientWrapper{
headers: d.headers,
}
ctx := metadata.NewContext(context.Background(), d.existing)
2016-11-02 19:21:53 +02:00
ctx = c.setHeaders(ctx)
md, _ := metadata.FromContext(ctx)
for k, v := range d.headers {
if d.overwrite && md[k] != v {
t.Fatalf("Expected %s=%s got %s=%s", k, v, k, md[k])
}
if !d.overwrite && md[k] != d.existing[k] {
t.Fatalf("Expected %s=%s got %s=%s", k, d.existing[k], k, md[k])
}
}
}
}