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"
@@ -182,6 +183,7 @@ func Test_RepoClone(t *testing.T) {
182183 for _ , tt := range tests {
183184 t .Run (tt .name , func (t * testing.T ) {
184185 reg := & httpmock.Registry {}
186+ defer reg .Verify (t )
185187 reg .Register (
186188 httpmock .GraphQL (`query RepositoryInfo\b` ),
187189 httpmock .StringResponse (`
@@ -196,10 +198,11 @@ func Test_RepoClone(t *testing.T) {
196198
197199 httpClient := & http.Client {Transport : reg }
198200
199- cs , restore := test .InitCmdStubber ()
200- defer restore ()
201-
202- cs .Stub ("" ) // git clone
201+ cs , restore := run .Stub ()
202+ defer restore (t )
203+ cs .Register (`git clone` , 0 , "" , func (s []string ) {
204+ assert .Equal (t , tt .want , strings .Join (s , " " ))
205+ })
203206
204207 output , err := runCloneCommand (httpClient , tt .args )
205208 if err != nil {
@@ -208,9 +211,6 @@ func Test_RepoClone(t *testing.T) {
208211
209212 assert .Equal (t , "" , output .String ())
210213 assert .Equal (t , "" , output .Stderr ())
211- assert .Equal (t , 1 , cs .Count )
212- assert .Equal (t , tt .want , strings .Join (cs .Calls [0 ].Args , " " ))
213- reg .Verify (t )
214214 })
215215 }
216216}
@@ -236,23 +236,20 @@ func Test_RepoClone_hasParent(t *testing.T) {
236236
237237 httpClient := & http.Client {Transport : reg }
238238
239- cs , restore := test .InitCmdStubber ()
240- defer restore ()
241-
242- cs .Stub ("" ) // git clone
243- cs .Stub ("" ) // git remote add
239+ cs , restore := run .Stub ()
240+ defer restore (t )
241+ cs .Register (`git clone` , 0 , "" )
242+ cs .Register (`git -C REPO remote add -f upstream https://github\.com/hubot/ORIG\.git` , 0 , "" )
244243
245244 _ , err := runCloneCommand (httpClient , "OWNER/REPO" )
246245 if err != nil {
247246 t .Fatalf ("error running command `repo clone`: %v" , err )
248247 }
249-
250- assert .Equal (t , 2 , cs .Count )
251- assert .Equal (t , "git -C REPO remote add -f upstream https://github.com/hubot/ORIG.git" , strings .Join (cs .Calls [1 ].Args , " " ))
252248}
253249
254250func Test_RepoClone_withoutUsername (t * testing.T ) {
255251 reg := & httpmock.Registry {}
252+ defer reg .Verify (t )
256253 reg .Register (
257254 httpmock .GraphQL (`query UserCurrent\b` ),
258255 httpmock .StringResponse (`
@@ -269,19 +266,12 @@ func Test_RepoClone_withoutUsername(t *testing.T) {
269266 }
270267 } } }
271268 ` ))
272- reg .Register (
273- httpmock .GraphQL (`query RepositoryFindParent\b` ),
274- httpmock .StringResponse (`
275- { "data": { "repository": {
276- "parent": null
277- } } }` ))
278269
279270 httpClient := & http.Client {Transport : reg }
280271
281- cs , restore := test .InitCmdStubber ()
282- defer restore ()
283-
284- cs .Stub ("" ) // git clone
272+ cs , restore := run .Stub ()
273+ defer restore (t )
274+ cs .Register (`git clone https://github\.com/OWNER/REPO\.git` , 0 , "" )
285275
286276 output , err := runCloneCommand (httpClient , "REPO" )
287277 if err != nil {
@@ -290,6 +280,4 @@ func Test_RepoClone_withoutUsername(t *testing.T) {
290280
291281 assert .Equal (t , "" , output .String ())
292282 assert .Equal (t , "" , output .Stderr ())
293- assert .Equal (t , 1 , cs .Count )
294- assert .Equal (t , "git clone https://github.com/OWNER/REPO.git" , strings .Join (cs .Calls [0 ].Args , " " ))
295283}
0 commit comments