2022-12-18 20:06:49 +03:00
|
|
|
package requestid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-05-07 19:41:15 +03:00
|
|
|
"go.unistack.org/micro/v4/metadata"
|
2022-12-18 20:06:49 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDefaultMetadataFunc(t *testing.T) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
nctx, err := DefaultMetadataFunc(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
imd, ok := metadata.FromIncomingContext(nctx)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("md missing in incoming context")
|
|
|
|
}
|
|
|
|
omd, ok := metadata.FromOutgoingContext(nctx)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("md missing in outgoing context")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, iok := imd.Get(DefaultMetadataKey)
|
|
|
|
_, ook := omd.Get(DefaultMetadataKey)
|
|
|
|
|
|
|
|
if !iok || !ook {
|
|
|
|
t.Fatalf("missing metadata key value")
|
|
|
|
}
|
|
|
|
}
|