X Tutup
Skip to content

Commit c63acf6

Browse files
committed
Migrate to new cmd stubber in misc. tests
1 parent 1717c8d commit c63acf6

File tree

5 files changed

+24
-37
lines changed

5 files changed

+24
-37
lines changed

pkg/cmd/gist/clone/clone_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/cli/cli/internal/config"
9+
"github.com/cli/cli/internal/run"
910
"github.com/cli/cli/pkg/cmdutil"
1011
"github.com/cli/cli/pkg/httpmock"
1112
"github.com/cli/cli/pkg/iostreams"
@@ -88,13 +89,15 @@ func Test_GistClone(t *testing.T) {
8889
for _, tt := range tests {
8990
t.Run(tt.name, func(t *testing.T) {
9091
reg := &httpmock.Registry{}
92+
defer reg.Verify(t)
9193

9294
httpClient := &http.Client{Transport: reg}
9395

94-
cs, restore := test.InitCmdStubber()
95-
defer restore()
96-
97-
cs.Stub("") // git clone
96+
cs, restore := run.Stub()
97+
defer restore(t)
98+
cs.Register(`git clone`, 0, "", func(s []string) {
99+
assert.Equal(t, tt.want, strings.Join(s, " "))
100+
})
98101

99102
output, err := runCloneCommand(httpClient, tt.args)
100103
if err != nil {
@@ -103,9 +106,6 @@ func Test_GistClone(t *testing.T) {
103106

104107
assert.Equal(t, "", output.String())
105108
assert.Equal(t, "", output.Stderr())
106-
assert.Equal(t, 1, cs.Count)
107-
assert.Equal(t, tt.want, strings.Join(cs.Calls[0].Args, " "))
108-
reg.Verify(t)
109109
})
110110
}
111111
}

pkg/cmd/gist/create/create_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package create
33
import (
44
"bytes"
55
"encoding/json"
6-
"github.com/cli/cli/test"
76
"io/ioutil"
87
"net/http"
98
"strings"
109
"testing"
1110

11+
"github.com/cli/cli/internal/run"
1212
"github.com/cli/cli/pkg/cmd/gist/shared"
1313
"github.com/cli/cli/pkg/cmdutil"
1414
"github.com/cli/cli/pkg/httpmock"
@@ -291,11 +291,10 @@ func Test_createRun(t *testing.T) {
291291
io, stdin, stdout, stderr := iostreams.Test()
292292
tt.opts.IO = io
293293

294-
cs, cmdTeardown := test.InitCmdStubber()
295-
defer cmdTeardown()
296-
294+
cs, teardown := run.Stub()
295+
defer teardown(t)
297296
if tt.opts.WebMode {
298-
cs.Stub("")
297+
cs.Register(`https://gist\.github\.com/aa5a315d61ae9438b18d$`, 0, "")
299298
}
300299

301300
t.Run(tt.name, func(t *testing.T) {
@@ -313,12 +312,6 @@ func Test_createRun(t *testing.T) {
313312
assert.Equal(t, tt.wantOut, stdout.String())
314313
assert.Equal(t, tt.wantStderr, stderr.String())
315314
assert.Equal(t, tt.wantParams, reqBody)
316-
317-
if tt.opts.WebMode {
318-
browserCall := cs.Calls[0].Args
319-
assert.Equal(t, browserCall[len(browserCall)-1], "https://gist.github.com/aa5a315d61ae9438b18d")
320-
}
321-
322315
reg.Verify(t)
323316
})
324317
}

pkg/cmd/pr/checks/checks_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"testing"
77

88
"github.com/cli/cli/internal/ghrepo"
9+
"github.com/cli/cli/internal/run"
910
"github.com/cli/cli/pkg/cmdutil"
1011
"github.com/cli/cli/pkg/httpmock"
1112
"github.com/cli/cli/pkg/iostreams"
12-
"github.com/cli/cli/test"
1313
"github.com/google/shlex"
1414
"github.com/stretchr/testify/assert"
1515
)
@@ -252,10 +252,9 @@ func TestChecksRun_web(t *testing.T) {
252252

253253
opts.IO = io
254254

255-
cs, teardown := test.InitCmdStubber()
256-
defer teardown()
257-
258-
cs.Stub("") // browser open
255+
cs, teardown := run.Stub()
256+
defer teardown(t)
257+
cs.Register(`https://github\.com/OWNER/REPO/pull/123/checks$`, 0, "")
259258

260259
err := checksRun(opts)
261260
assert.NoError(t, err)

pkg/cmd/pr/close/close_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/cli/cli/internal/config"
1111
"github.com/cli/cli/internal/ghrepo"
12+
"github.com/cli/cli/internal/run"
1213
"github.com/cli/cli/pkg/cmdutil"
1314
"github.com/cli/cli/pkg/httpmock"
1415
"github.com/cli/cli/pkg/iostreams"
@@ -135,13 +136,11 @@ func TestPrClose_deleteBranch(t *testing.T) {
135136
httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"),
136137
httpmock.StringResponse(`{}`))
137138

138-
cs, cmdTeardown := test.InitCmdStubber()
139-
defer cmdTeardown()
139+
cs, cmdTeardown := run.Stub()
140+
defer cmdTeardown(t)
140141

141-
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
142-
cs.Stub("") // git rev-parse --verify blueberries`
143-
cs.Stub("") // git branch -d
144-
cs.Stub("") // git push origin --delete blueberries
142+
cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "")
143+
cs.Register(`git branch -D blueberries`, 0, "")
145144

146145
output, err := runCommand(http, true, `96 --delete-branch`)
147146
if err != nil {

pkg/cmd/repo/view/view_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88

99
"github.com/MakeNowJust/heredoc"
1010
"github.com/cli/cli/internal/ghrepo"
11+
"github.com/cli/cli/internal/run"
1112
"github.com/cli/cli/pkg/cmdutil"
1213
"github.com/cli/cli/pkg/httpmock"
1314
"github.com/cli/cli/pkg/iostreams"
14-
"github.com/cli/cli/test"
1515
"github.com/google/shlex"
1616
"github.com/stretchr/testify/assert"
1717
)
@@ -132,18 +132,14 @@ func Test_RepoView_Web(t *testing.T) {
132132
t.Run(tt.name, func(t *testing.T) {
133133
io.SetStdoutTTY(tt.stdoutTTY)
134134

135-
cs, teardown := test.InitCmdStubber()
136-
defer teardown()
137-
138-
cs.Stub("") // browser open
135+
cs, teardown := run.Stub()
136+
defer teardown(t)
137+
cs.Register(`https://github\.com/OWNER/REPO$`, 0, "")
139138

140139
if err := viewRun(opts); err != nil {
141140
t.Errorf("viewRun() error = %v", err)
142141
}
143142
assert.Equal(t, "", stdout.String())
144-
assert.Equal(t, 1, len(cs.Calls))
145-
call := cs.Calls[0]
146-
assert.Equal(t, "https://github.com/OWNER/REPO", call.Args[len(call.Args)-1])
147143
assert.Equal(t, tt.wantStderr, stderr.String())
148144
reg.Verify(t)
149145
})

0 commit comments

Comments
 (0)
X Tutup