(t *testing.T)
| 151 | } |
| 152 | |
| 153 | func 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 | |
| 209 | func TestContextHasParent(t *testing.T) { |
| 210 | sharedCtx, cancel := context.WithCancel(context.WithValue(context.Background(), struct{}{}, struct{}{})) |
nothing calls this directly
no test coverage detected