MCPcopy Index your code
hub / github.com/smallstep/cli / TestInjectContext

Function TestInjectContext

internal/command/inject_test.go:27–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25}
26
27func 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
55func TestInjectContextWithMiddleware(t *testing.T) {
56 t.Parallel()

Callers

nothing calls this directly

Calls 2

CLIContextFromContextFunction · 0.85
InjectContextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…