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

Function TestContextRoot

pkg/util/test/assertions/context_test.go:153–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestContextRoot(t *testing.T) {
154 root := context.Background()
155
156 for _, tc := range []struct {
157 Name string
158 Context context.Context
159 }{
160 {
161 Name: "4",
162 Context: context.WithValue(
163 context.WithValue(
164 context.WithValue(
165 context.WithValue(
166 root, "A", nil),
167 "B", nil),
168 struct{}{}, nil),
169 struct{}{}, nil),
170 },
171 {
172 Name: "log.NewContext",
173 Context: log.NewContext(
174 log.NewContext(
175 root, log.Noop),
176 log.Noop,
177 ),
178 },
179 {
180 Name: "errorcontext.New",
181 Context: func() (ctx context.Context) {
182 ctx, _ = errorcontext.New(root)
183 ctx, _ = errorcontext.New(ctx)
184 return
185 }(),
186 },
187 {
188 Name: "0",
189 Context: root,
190 },
191 {
192 Name: "nil",
193 Context: nil,
194 },
195 } {
196 t.Run(tc.Name, func(t *testing.T) {
197 a := assertions.New(t)
198 a.So(func() {
199 expected := root
200 if tc.Context == nil {
201 expected = nil
202 }
203 a.So(utilassertions.ContextRoot(tc.Context), should.Equal, expected)
204 }, should.NotPanic)
205 })
206 }
207}
208
209func TestContextHasParent(t *testing.T) {
210 sharedCtx, cancel := context.WithCancel(context.WithValue(context.Background(), struct{}{}, struct{}{}))

Callers

nothing calls this directly

Calls 4

NewContextFunction · 0.92
NewFunction · 0.92
RunMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected