(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestContextDecoupling(t *testing.T) { |
| 29 | a := assertions.New(t) |
| 30 | |
| 31 | c, err := component.New(test.GetLogger(t), &component.Config{}) |
| 32 | a.So(err, should.BeNil) |
| 33 | |
| 34 | dl := time.Now().Add(1 * time.Second) |
| 35 | |
| 36 | ctx := test.Context() |
| 37 | ctx = context.WithValue(ctx, "key", "value") |
| 38 | ctx, cancel := context.WithDeadline(ctx, dl) |
| 39 | defer cancel() |
| 40 | |
| 41 | ctx = c.FromRequestContext(ctx) |
| 42 | deadline, set := ctx.Deadline() |
| 43 | a.So(deadline, should.NotEqual, dl) |
| 44 | a.So(set, should.BeFalse) |
| 45 | |
| 46 | select { |
| 47 | case <-ctx.Done(): |
| 48 | t.Fatal("Context expired") |
| 49 | case <-time.After(time.Second): |
| 50 | a.So(ctx.Err(), should.BeNil) |
| 51 | } |
| 52 | |
| 53 | val := ctx.Value("key") |
| 54 | strVal, ok := val.(string) |
| 55 | a.So(ok, should.BeTrue) |
| 56 | a.So(strVal, should.Equal, "value") |
| 57 | } |
nothing calls this directly
no test coverage detected