@@ -363,12 +363,17 @@ func TestRepoClone(t *testing.T) {
363363 }
364364 for _ , tt := range tests {
365365 t .Run (tt .name , func (t * testing.T ) {
366- var seenCmd * exec.Cmd
367- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
368- seenCmd = cmd
369- return & test.OutputStub {}
370- })
371- defer restoreCmd ()
366+ http := initFakeHTTP ()
367+ http .StubResponse (200 , bytes .NewBufferString (`
368+ { "data": { "repository": {
369+ "parent": null
370+ } } }
371+ ` ))
372+
373+ cs , restore := test .InitCmdStubber ()
374+ defer restore ()
375+
376+ cs .Stub ("" ) // git clone
372377
373378 output , err := RunCommand (repoCloneCmd , tt .args )
374379 if err != nil {
@@ -377,15 +382,38 @@ func TestRepoClone(t *testing.T) {
377382
378383 eq (t , output .String (), "" )
379384 eq (t , output .Stderr (), "" )
380-
381- if seenCmd == nil {
382- t .Fatal ("expected a command to run" )
383- }
384- eq (t , strings .Join (seenCmd .Args , " " ), tt .want )
385+ eq (t , cs .Count , 1 )
386+ eq (t , strings .Join (cs .Calls [0 ].Args , " " ), tt .want )
385387 })
386388 }
387389}
388390
391+ func TestRepoClone_hasParent (t * testing.T ) {
392+ http := initFakeHTTP ()
393+ http .StubResponse (200 , bytes .NewBufferString (`
394+ { "data": { "repository": {
395+ "parent": {
396+ "owner": {"login": "hubot"},
397+ "name": "ORIG"
398+ }
399+ } } }
400+ ` ))
401+
402+ cs , restore := test .InitCmdStubber ()
403+ defer restore ()
404+
405+ cs .Stub ("" ) // git clone
406+ cs .Stub ("" ) // git remote add
407+
408+ _ , err := RunCommand (repoCloneCmd , "repo clone OWNER/REPO" )
409+ if err != nil {
410+ t .Fatalf ("error running command `repo clone`: %v" , err )
411+ }
412+
413+ eq (t , cs .Count , 2 )
414+ eq (t , strings .Join (cs .Calls [1 ].Args , " " ), "git -C REPO remote add upstream https://github.com/hubot/ORIG.git" )
415+ }
416+
389417func TestRepoCreate (t * testing.T ) {
390418 ctx := context .NewBlank ()
391419 ctx .SetBranch ("master" )
0 commit comments