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

Function TestErrorContext

pkg/errorcontext/errorcontext_test.go:52–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestErrorContext(t *testing.T) {
53 a := assertions.New(t)
54
55 {
56 err := errors.New("foo")
57 ctx, cancel := errorcontext.New(test.Context())
58 cancel(err)
59 select {
60 case <-ctx.Done():
61 a.So(ctx.Err(), should.Equal, err)
62 default:
63 t.Error("Context was not done")
64 }
65
66 cancel(errors.New("other"))
67 <-ctx.Done()
68 a.So(ctx.Err(), should.Equal, err)
69 }
70
71 {
72 ctx, cancel := context.WithCancel(test.Context())
73 ctx, _ = errorcontext.New(ctx)
74 cancel()
75 select {
76 case <-ctx.Done():
77 a.So(ctx.Err(), should.Equal, context.Canceled)
78 default:
79 t.Error("Context was not done")
80 }
81 }
82}

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
ContextFunction · 0.92
DoneMethod · 0.80
NewMethod · 0.65
ErrorMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected