MCPcopy
hub / github.com/urfave/cli / TestCompletionRunsBeforeChain

Function TestCompletionRunsBeforeChain

completion_test.go:450–479  ·  completion_test.go::TestCompletionRunsBeforeChain
(t *testing.T)

Source from the content-addressed store, hash-verified

448}
449
450func TestCompletionRunsBeforeChain(t *testing.T) {
451 type contextKey struct{}
452
453 out := &bytes.Buffer{}
454 cmd := &Command{
455 EnableShellCompletion: true,
456 Writer: out,
457 Before: func(ctx context.Context, cmd *Command) (context.Context, error) {
458 return context.WithValue(ctx, contextKey{}, "ready"), nil
459 },
460 Commands: []*Command{
461 {
462 Name: "index",
463 Commands: []*Command{
464 {
465 Name: "show",
466 ShellComplete: func(ctx context.Context, cmd *Command) {
467 fmt.Fprintln(cmd.Root().Writer, ctx.Value(contextKey{}))
468 },
469 Action: func(ctx context.Context, cmd *Command) error { return nil },
470 },
471 },
472 },
473 },
474 }
475
476 r := require.New(t)
477 r.NoError(cmd.Run(buildTestContext(t), []string{"foo", "index", "show", completionFlag}))
478 r.Equal("ready\n", out.String())
479}
480
481func TestCompletionReturnsBeforeError(t *testing.T) {
482 beforeErr := errors.New("load config")

Callers

nothing calls this directly

Calls 5

RootMethod · 0.95
RunMethod · 0.95
buildTestContextFunction · 0.85
ValueMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected