X Tutup
Skip to content

Commit dcedd32

Browse files
author
vilmibm
committed
use newer command stubbing in tests
1 parent f536901 commit dcedd32

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

git/git_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package git
33
import (
44
"os/exec"
55
"reflect"
6-
"strings"
76
"testing"
87

98
"github.com/cli/cli/internal/run"
109
"github.com/cli/cli/test"
11-
"github.com/stretchr/testify/assert"
1210
)
1311

1412
func Test_UncommittedChangeCount(t *testing.T) {
@@ -199,18 +197,15 @@ func TestAddUpstreamRemote(t *testing.T) {
199197
}
200198
for _, tt := range tests {
201199
t.Run(tt.name, func(t *testing.T) {
202-
cs, restore := test.InitCmdStubber()
203-
defer restore()
200+
cs, cmdTeardown := run.Stub()
201+
defer cmdTeardown(t)
204202

205-
cs.Stub("") // git remote add -f
203+
cs.Register(tt.want, 0, "")
206204

207205
err := AddUpstreamRemote(tt.upstreamURL, tt.cloneDir, tt.branches)
208206
if err != nil {
209207
t.Fatalf("error running command `git remote add -f`: %v", err)
210208
}
211-
212-
assert.Equal(t, 1, cs.Count)
213-
assert.Equal(t, tt.want, strings.Join(cs.Calls[0].Args, " "))
214209
})
215210
}
216211
}

pkg/cmd/repo/clone/clone_test.go

Lines changed: 5 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"
@@ -228,19 +229,16 @@ func Test_RepoClone_hasParent(t *testing.T) {
228229

229230
httpClient := &http.Client{Transport: reg}
230231

231-
cs, restore := test.InitCmdStubber()
232-
defer restore()
232+
cs, cmdTeardown := run.Stub()
233+
defer cmdTeardown(t)
233234

234-
cs.Stub("") // git clone
235-
cs.Stub("") // git remote add
235+
cs.Register(`git clone https://github.com/OWNER/REPO.git`, 0, "")
236+
cs.Register(`git -C REPO remote add -t master -f upstream https://github.com/hubot/ORIG.git`, 0, "")
236237

237238
_, err := runCloneCommand(httpClient, "OWNER/REPO")
238239
if err != nil {
239240
t.Fatalf("error running command `repo clone`: %v", err)
240241
}
241-
242-
assert.Equal(t, 2, cs.Count)
243-
assert.Equal(t, "git -C REPO remote add -t master -f upstream https://github.com/hubot/ORIG.git", strings.Join(cs.Calls[1].Args, " "))
244242
}
245243

246244
func Test_RepoClone_withoutUsername(t *testing.T) {

0 commit comments

Comments
 (0)
X Tutup