micro/util/ctx/ctx_test.go
Vasiliy Tolstov 5eb0e56373 move all imports to own domain
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-10-02 19:55:07 +03:00

42 lines
764 B
Go

package ctx
import (
"net/http"
"testing"
"go.unistack.org/micro/v3/metadata"
)
func TestRequestToContext(t *testing.T) {
testData := []struct {
request *http.Request
expect metadata.Metadata
}{
{
&http.Request{
Header: http.Header{
"Foo1": []string{"bar"},
"Foo2": []string{"bar", "baz"},
},
},
metadata.Metadata{
"Foo1": "bar",
"Foo2": "bar,baz",
},
},
}
for _, d := range testData {
ctx := FromRequest(d.request)
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
t.Fatalf("Expected metadata for request %+v", d.request)
}
for k, v := range d.expect {
if val := md[k]; val != v {
t.Fatalf("Expected %s for key %s for expected md %+v, got md %+v", v, k, d.expect, md)
}
}
}
}