(t *testing.T)
| 25 | } |
| 26 | |
| 27 | func TestInjectContext(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | fnCalled := false |
| 31 | |
| 32 | type contextKey struct{} |
| 33 | |
| 34 | ctx := context.Background() |
| 35 | ctx = context.WithValue(ctx, contextKey{}, true) |
| 36 | |
| 37 | fn := func(ctx context.Context) error { |
| 38 | assert.True(t, ctx.Value(contextKey{}).(bool)) |
| 39 | clictx := CLIContextFromContext(ctx) |
| 40 | assert.NotNil(t, clictx) |
| 41 | fnCalled = true |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | got := InjectContext(ctx, fn) |
| 46 | |
| 47 | assert.NotNil(t, got) |
| 48 | |
| 49 | // execute the function to ensure injected context is OK |
| 50 | err := got(new(cli.Context)) |
| 51 | assert.NoError(t, err) |
| 52 | assert.True(t, fnCalled) |
| 53 | } |
| 54 | |
| 55 | func TestInjectContextWithMiddleware(t *testing.T) { |
| 56 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…