MCPcopy Index your code
hub / github.com/cli/cli / TestExpandAlias

Function TestExpandAlias

pkg/cmd/root/alias_test.go:10–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestExpandAlias(t *testing.T) {
11 tests := []struct {
12 name string
13 expansion string
14 args []string
15 wantExpanded []string
16 wantErr string
17 }{
18 {
19 name: "no expansion",
20 expansion: "pr status",
21 args: []string{},
22 wantExpanded: []string{"pr", "status"},
23 },
24 {
25 name: "adding arguments after expansion",
26 expansion: "pr checkout",
27 args: []string{"123"},
28 wantExpanded: []string{"pr", "checkout", "123"},
29 },
30 {
31 name: "not enough arguments for expansion",
32 expansion: `issue list --author="$1" --label="$2"`,
33 args: []string{},
34 wantErr: `not enough arguments for alias: issue list --author="$1" --label="$2"`,
35 },
36 {
37 name: "not enough arguments for expansion 2",
38 expansion: `issue list --author="$1" --label="$2"`,
39 args: []string{"vilmibm"},
40 wantErr: `not enough arguments for alias: issue list --author="vilmibm" --label="$2"`,
41 },
42 {
43 name: "satisfy expansion arguments",
44 expansion: `issue list --author="$1" --label="$2"`,
45 args: []string{"vilmibm", "help wanted"},
46 wantExpanded: []string{"issue", "list", "--author=vilmibm", "--label=help wanted"},
47 },
48 {
49 name: "mixed positional and non-positional arguments",
50 expansion: `issue list --author="$1" --label="$2"`,
51 args: []string{"vilmibm", "epic", "-R", "monalisa/testing"},
52 wantExpanded: []string{"issue", "list", "--author=vilmibm", "--label=epic", "-R", "monalisa/testing"},
53 },
54 {
55 name: "dollar in expansion",
56 expansion: `issue list --author="$1" --assignee="$1"`,
57 args: []string{"$coolmoney$"},
58 wantExpanded: []string{"issue", "list", "--author=$coolmoney$", "--assignee=$coolmoney$"},
59 },
60 }
61 for _, tt := range tests {
62 t.Run(tt.name, func(t *testing.T) {
63 gotExpanded, err := expandAlias(tt.expansion, tt.args)
64 if tt.wantErr != "" {
65 assert.Nil(t, gotExpanded)
66 assert.EqualError(t, err, tt.wantErr)
67 return

Callers

nothing calls this directly

Calls 3

expandAliasFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected