MCPcopy
hub / github.com/cli/cli / TestNewCmdCompletion

Function TestNewCmdCompletion

pkg/cmd/completion/completion_test.go:12–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestNewCmdCompletion(t *testing.T) {
13 tests := []struct {
14 name string
15 args string
16 wantOut string
17 wantErr string
18 }{
19 {
20 name: "no arguments",
21 args: "completion",
22 wantOut: "complete -o default -F __start_gh gh",
23 },
24 {
25 name: "zsh completion",
26 args: "completion -s zsh",
27 wantOut: "#compdef gh",
28 },
29 {
30 name: "fish completion",
31 args: "completion -s fish",
32 wantOut: "complete -c gh ",
33 },
34 {
35 name: "PowerShell completion",
36 args: "completion -s powershell",
37 wantOut: "Register-ArgumentCompleter",
38 },
39 {
40 name: "unsupported shell",
41 args: "completion -s csh",
42 wantErr: "invalid argument \"csh\" for \"-s, --shell\" flag: valid values are {bash|zsh|fish|powershell}",
43 },
44 }
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 ios, _, stdout, stderr := iostreams.Test()
48 completeCmd := NewCmdCompletion(ios)
49 rootCmd := &cobra.Command{Use: "gh"}
50 rootCmd.AddCommand(completeCmd)
51
52 argv, err := shlex.Split(tt.args)
53 if err != nil {
54 t.Fatalf("argument splitting error: %v", err)
55 }
56 rootCmd.SetArgs(argv)
57 rootCmd.SetOut(stderr)
58 rootCmd.SetErr(stderr)
59
60 _, err = rootCmd.ExecuteC()
61 if tt.wantErr != "" {
62 if err == nil || err.Error() != tt.wantErr {
63 t.Fatalf("expected error %q, got %q", tt.wantErr, err)
64 }
65 return
66 }
67 if err != nil {
68 t.Fatalf("error executing command: %v", err)
69 }

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
NewCmdCompletionFunction · 0.85
ContainsMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected