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()
|
2024-03-10 22:14:28 +03:00
|
|
|
var err error
|
2022-12-18 20:06:49 +03:00
|
|
|
|
2024-03-10 22:14:28 +03:00
|
|
|
ctx, err = DefaultMetadataFunc(ctx)
|
2022-12-18 20:06:49 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%v", err)
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:14:28 +03:00
|
|
|
imd, ok := metadata.FromIncomingContext(ctx)
|
2022-12-18 20:06:49 +03:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("md missing in incoming context")
|
|
|
|
}
|
2024-03-10 22:14:28 +03:00
|
|
|
omd, ok := metadata.FromOutgoingContext(ctx)
|
2022-12-18 20:06:49 +03:00
|
|
|
if !ok {
|
|
|
|
t.Fatalf("md missing in outgoing context")
|
|
|
|
}
|
|
|
|
|
2024-03-10 22:14:28 +03:00
|
|
|
iv, iok := imd.Get(DefaultMetadataKey)
|
|
|
|
ov, ook := omd.Get(DefaultMetadataKey)
|
2022-12-18 20:06:49 +03:00
|
|
|
|
|
|
|
if !iok || !ook {
|
|
|
|
t.Fatalf("missing metadata key value")
|
|
|
|
}
|
2024-03-10 22:14:28 +03:00
|
|
|
if iv != ov {
|
|
|
|
t.Fatalf("invalid metadata key value")
|
|
|
|
}
|
2022-12-18 20:06:49 +03:00
|
|
|
}
|