|
1 | 1 | package rename |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "net/http" |
5 | 6 | "testing" |
6 | 7 |
|
7 | 8 | "github.com/cli/cli/v2/context" |
8 | 9 | "github.com/cli/cli/v2/git" |
9 | 10 | "github.com/cli/cli/v2/internal/config" |
10 | 11 | "github.com/cli/cli/v2/internal/ghrepo" |
| 12 | + "github.com/cli/cli/v2/pkg/cmdutil" |
11 | 13 | "github.com/cli/cli/v2/pkg/httpmock" |
12 | 14 | "github.com/cli/cli/v2/pkg/iostreams" |
13 | 15 | "github.com/cli/cli/v2/pkg/prompt" |
| 16 | + "github.com/google/shlex" |
14 | 17 | "github.com/stretchr/testify/assert" |
15 | 18 | ) |
16 | 19 |
|
17 | | -// func TestNewCmdRename(t *testing.T) { |
18 | | -// testCases := []struct { |
19 | | -// name string |
20 | | -// input string |
21 | | -// output RenameOptions |
22 | | -// errMsg string |
23 | | -// tty bool |
24 | | -// wantErr bool |
25 | | -// }{ |
26 | | -// { |
27 | | -// name: "no arguments no tty", |
28 | | -// input: "", |
29 | | -// errMsg: "could not prompt: proceed with prompt", |
30 | | -// wantErr: true, |
31 | | -// tty: false, |
32 | | -// }, |
33 | | -// { |
34 | | -// name: "one argument", |
35 | | -// input: "REPO", |
36 | | -// output: RenameOptions{ |
37 | | -// newRepoSelector: "REPO", |
38 | | -// }, |
39 | | -// }, |
40 | | -// { |
41 | | -// name: "full flag argument", |
42 | | -// input: "--repo OWNER/REPO NEW_REPO", |
43 | | -// output: RenameOptions{ |
44 | | -// newRepoSelector: "NEW_REPO", |
45 | | -// }, |
46 | | -// }, |
47 | | -// } |
48 | | -// for _, tt := range testCases { |
49 | | -// t.Run(tt.name, func(t *testing.T) { |
50 | | -// io, _, _, _ := iostreams.Test() |
51 | | -// io.SetStdinTTY(tt.tty) |
52 | | -// io.SetStdoutTTY(tt.tty) |
53 | | -// f := &cmdutil.Factory{ |
54 | | -// IOStreams: io, |
55 | | -// } |
| 20 | +func TestNewCmdRename(t *testing.T) { |
| 21 | + testCases := []struct { |
| 22 | + name string |
| 23 | + input string |
| 24 | + output RenameOptions |
| 25 | + errMsg string |
| 26 | + tty bool |
| 27 | + wantErr bool |
| 28 | + }{ |
| 29 | + { |
| 30 | + name: "no arguments no tty", |
| 31 | + input: "", |
| 32 | + errMsg: "could not prompt: proceed with prompt", |
| 33 | + wantErr: true, |
| 34 | + tty: false, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "one argument", |
| 38 | + input: "REPO", |
| 39 | + output: RenameOptions{ |
| 40 | + newRepoSelector: "REPO", |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "full flag argument", |
| 45 | + input: "--repo OWNER/REPO NEW_REPO", |
| 46 | + output: RenameOptions{ |
| 47 | + newRepoSelector: "NEW_REPO", |
| 48 | + }, |
| 49 | + }, |
| 50 | + } |
| 51 | + for _, tt := range testCases { |
| 52 | + t.Run(tt.name, func(t *testing.T) { |
| 53 | + io, _, _, _ := iostreams.Test() |
| 54 | + io.SetStdinTTY(tt.tty) |
| 55 | + io.SetStdoutTTY(tt.tty) |
| 56 | + f := &cmdutil.Factory{ |
| 57 | + IOStreams: io, |
| 58 | + } |
56 | 59 |
|
57 | | -// argv, err := shlex.Split(tt.input) |
58 | | -// assert.NoError(t, err) |
59 | | -// var gotOpts *RenameOptions |
60 | | -// cmd := NewCmdRename(f, func(opts *RenameOptions) error { |
61 | | -// gotOpts = opts |
62 | | -// return nil |
63 | | -// }) |
64 | | -// cmd.SetArgs(argv) |
65 | | -// cmd.SetIn(&bytes.Buffer{}) |
66 | | -// cmd.SetOut(&bytes.Buffer{}) |
67 | | -// cmd.SetErr(&bytes.Buffer{}) |
| 60 | + argv, err := shlex.Split(tt.input) |
| 61 | + assert.NoError(t, err) |
| 62 | + var gotOpts *RenameOptions |
| 63 | + cmd := NewCmdRename(f, func(opts *RenameOptions) error { |
| 64 | + gotOpts = opts |
| 65 | + return nil |
| 66 | + }) |
| 67 | + cmd.SetArgs(argv) |
| 68 | + cmd.SetIn(&bytes.Buffer{}) |
| 69 | + cmd.SetOut(&bytes.Buffer{}) |
| 70 | + cmd.SetErr(&bytes.Buffer{}) |
68 | 71 |
|
69 | | -// _, err = cmd.ExecuteC() |
70 | | -// if tt.wantErr { |
71 | | -// assert.Error(t, err) |
72 | | -// return |
73 | | -// } |
74 | | -// assert.NoError(t, err) |
75 | | -// assert.Equal(t, tt.output.newRepoSelector, gotOpts.newRepoSelector) |
76 | | -// }) |
77 | | -// } |
78 | | -// } |
| 72 | + _, err = cmd.ExecuteC() |
| 73 | + if tt.wantErr { |
| 74 | + assert.Error(t, err) |
| 75 | + return |
| 76 | + } |
| 77 | + assert.NoError(t, err) |
| 78 | + assert.Equal(t, tt.output.newRepoSelector, gotOpts.newRepoSelector) |
| 79 | + }) |
| 80 | + } |
| 81 | +} |
79 | 82 |
|
80 | 83 | func TestRenameRun(t *testing.T) { |
81 | 84 | testCases := []struct { |
|
0 commit comments