MCPcopy
hub / github.com/spf13/cobra / TestPlugin

Function TestPlugin

command_test.go:372–391  ·  view source on GitHub ↗

TestPlugin checks usage as plugin for another command such as kubectl. The executable is `kubectl-plugin`, but we run it as `kubectl plugin`. The help text should reflect the way we run the command.

(t *testing.T)

Source from the content-addressed store, hash-verified

370// executable is `kubectl-plugin`, but we run it as `kubectl plugin`. The help
371// text should reflect the way we run the command.
372func TestPlugin(t *testing.T) {
373 cmd := &Command{
374 Use: "kubectl-plugin",
375 Version: "1.0.0",
376 Args: NoArgs,
377 Annotations: map[string]string{
378 CommandDisplayNameAnnotation: "kubectl plugin",
379 },
380 Run: emptyRun,
381 }
382
383 cmdHelp, err := executeCommand(cmd, "-h")
384 if err != nil {
385 t.Errorf("Unexpected error: %v", err)
386 }
387
388 checkStringContains(t, cmdHelp, "kubectl plugin [flags]")
389 checkStringContains(t, cmdHelp, "help for kubectl plugin")
390 checkStringContains(t, cmdHelp, "version for kubectl plugin")
391}
392
393// TestPluginWithSubCommands checks usage as plugin with sub commands.
394func TestPluginWithSubCommands(t *testing.T) {

Callers

nothing calls this directly

Calls 2

executeCommandFunction · 0.85
checkStringContainsFunction · 0.70

Tested by

no test coverage detected