Skip to content

Commit 4e30fd5

Browse files
committed
uncommented tests
1 parent dc0b9bc commit 4e30fd5

File tree

1 file changed

+63
-60
lines changed

1 file changed

+63
-60
lines changed

pkg/cmd/repo/rename/rename_test.go

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,84 @@
11
package rename
22

33
import (
4+
"bytes"
45
"net/http"
56
"testing"
67

78
"github.com/cli/cli/v2/context"
89
"github.com/cli/cli/v2/git"
910
"github.com/cli/cli/v2/internal/config"
1011
"github.com/cli/cli/v2/internal/ghrepo"
12+
"github.com/cli/cli/v2/pkg/cmdutil"
1113
"github.com/cli/cli/v2/pkg/httpmock"
1214
"github.com/cli/cli/v2/pkg/iostreams"
1315
"github.com/cli/cli/v2/pkg/prompt"
16+
"github.com/google/shlex"
1417
"github.com/stretchr/testify/assert"
1518
)
1619

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+
}
5659

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{})
6871

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+
}
7982

8083
func TestRenameRun(t *testing.T) {
8184
testCases := []struct {

0 commit comments

Comments
 (0)