-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata_test.go
More file actions
45 lines (36 loc) · 889 Bytes
/
metadata_test.go
File metadata and controls
45 lines (36 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package forge
import (
"context"
"testing"
)
func TestWithMetadataAndFromContext(t *testing.T) {
ctx := context.Background()
m := Metadata{Values: map[string]string{"key": "value"}}
ctx = WithMetadata(ctx, m)
got, ok := MetadataFromContext(ctx)
if !ok {
t.Fatal("expected metadata in context")
}
if got.Values["key"] != "value" {
t.Errorf("got %q, want %q", got.Values["key"], "value")
}
}
func TestMetadataFromContextMissing(t *testing.T) {
ctx := context.Background()
_, ok := MetadataFromContext(ctx)
if ok {
t.Fatal("expected no metadata in context")
}
}
func TestWithMetadataNilMap(t *testing.T) {
ctx := context.Background()
m := Metadata{Values: nil}
ctx = WithMetadata(ctx, m)
got, ok := MetadataFromContext(ctx)
if !ok {
t.Fatal("expected metadata in context")
}
if got.Values == nil {
t.Fatal("expected Values map to be initialized")
}
}