MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestContext

Function TestContext

pkg/log/context_test.go:26–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestContext(t *testing.T) {
27 a := assertions.New(t)
28 ctx := context.Background()
29
30 logger := NewLogger(NoopHandler)
31
32 a.So(FromContext(ctx), should.NotBeNil)
33 a.So(FromContext(ctx), should.Equal, Noop)
34
35 ctx = NewContext(ctx, logger)
36
37 a.So(FromContext(ctx), should.Equal, logger)
38
39 t.Run("NewContextWithField", func(t *testing.T) {
40 a := assertions.New(t)
41 withKV := FromContext(NewContextWithField(ctx, "key", "value")).(Entry)
42 fields := withKV.Fields().Fields()
43 v, ok := fields["key"]
44 a.So(ok, should.BeTrue)
45 a.So(v, should.Equal, "value")
46 })
47
48 t.Run("NewContextWithFields", func(t *testing.T) {
49 a := assertions.New(t)
50 withKV := FromContext(NewContextWithFields(ctx, Fields("key", "value"))).(Entry)
51 fields := withKV.Fields().Fields()
52 v, ok := fields["key"]
53 a.So(ok, should.BeTrue)
54 a.So(v, should.Equal, "value")
55 })
56}

Callers

nothing calls this directly

Calls 9

NewLoggerFunction · 0.85
NewContextWithFieldFunction · 0.85
NewContextWithFieldsFunction · 0.85
FieldsFunction · 0.85
FromContextFunction · 0.70
NewContextFunction · 0.70
NewMethod · 0.65
RunMethod · 0.65
FieldsMethod · 0.65

Tested by

no test coverage detected