metadata: allow to modify metadata via SetXXX functions

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-09 12:46:14 +03:00
parent 0e51a79bb6
commit 927c7ea3c2
3 changed files with 76 additions and 9 deletions

View File

@@ -2,9 +2,32 @@ package metadata
import (
"context"
"fmt"
"testing"
)
func testCtx(ctx context.Context) {
md := New(2)
md.Set("Key1", "Val1_new")
md.Set("Key3", "Val3")
SetOutgoingContext(ctx, md)
}
func TestPassing(t *testing.T) {
ctx := context.TODO()
md1 := New(2)
md1.Set("Key1", "Val1")
md1.Set("Key2", "Val2")
ctx = NewIncomingContext(ctx, md1)
testCtx(ctx)
md, ok := FromOutgoingContext(ctx)
if !ok {
t.Fatalf("missing metadata from outgoing context")
}
fmt.Printf("%#+v\n", md)
}
func TestMerge(t *testing.T) {
omd := Metadata{
"key1": "val1",