(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func 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 | } |
nothing calls this directly
no test coverage detected