77 "io/ioutil"
88 "net/http"
99 "os"
10- "os/exec"
1110 "strings"
1211 "testing"
1312
@@ -281,13 +280,14 @@ func TestIssueCreate_continueInBrowser(t *testing.T) {
281280 },
282281 })
283282
284- var seenCmd * exec.Cmd
285- //nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
286- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
287- seenCmd = cmd
288- return & test.OutputStub {}
283+ cs , cmdTeardown := run .Stub ()
284+ defer cmdTeardown (t )
285+
286+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
287+ cs .Register (`https://github\.com` , 0 , "" , func (args []string ) {
288+ url := strings .ReplaceAll (args [len (args )- 1 ], "^" , "" )
289+ assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?body=body&title=hello" , url )
289290 })
290- defer restoreCmd ()
291291
292292 output , err := runCommand (http , true , `-b body` )
293293 if err != nil {
@@ -296,17 +296,11 @@ func TestIssueCreate_continueInBrowser(t *testing.T) {
296296
297297 assert .Equal (t , "" , output .String ())
298298 assert .Equal (t , heredoc .Doc (`
299-
299+
300300 Creating issue in OWNER/REPO
301-
301+
302302 Opening github.com/OWNER/REPO/issues/new in your browser.
303303 ` ), output .Stderr ())
304-
305- if seenCmd == nil {
306- t .Fatal ("expected a command to run" )
307- }
308- url := strings .ReplaceAll (seenCmd .Args [len (seenCmd .Args )- 1 ], "^" , "" )
309- assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?body=body&title=hello" , url )
310304}
311305
312306func TestIssueCreate_metadata (t * testing.T ) {
@@ -419,24 +413,20 @@ func TestIssueCreate_web(t *testing.T) {
419413 ` ),
420414 )
421415
422- var seenCmd * exec.Cmd
423- //nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
424- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
425- seenCmd = cmd
426- return & test.OutputStub {}
416+ cs , cmdTeardown := run .Stub ()
417+ defer cmdTeardown (t )
418+
419+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
420+ cs .Register (`https://github\.com` , 0 , "" , func (args []string ) {
421+ url := strings .ReplaceAll (args [len (args )- 1 ], "^" , "" )
422+ assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?assignees=MonaLisa" , url )
427423 })
428- defer restoreCmd ()
429424
430425 output , err := runCommand (http , true , `--web -a @me` )
431426 if err != nil {
432427 t .Errorf ("error running command `issue create`: %v" , err )
433428 }
434429
435- if seenCmd == nil {
436- t .Fatal ("expected a command to run" )
437- }
438- url := seenCmd .Args [len (seenCmd .Args )- 1 ]
439- assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?assignees=MonaLisa" , url )
440430 assert .Equal (t , "" , output .String ())
441431 assert .Equal (t , "Opening github.com/OWNER/REPO/issues/new in your browser.\n " , output .Stderr ())
442432}
@@ -445,24 +435,20 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
445435 http := & httpmock.Registry {}
446436 defer http .Verify (t )
447437
448- var seenCmd * exec.Cmd
449- //nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
450- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
451- seenCmd = cmd
452- return & test.OutputStub {}
438+ cs , cmdTeardown := run .Stub ()
439+ defer cmdTeardown (t )
440+
441+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
442+ cs .Register (`https://github\.com` , 0 , "" , func (args []string ) {
443+ url := strings .ReplaceAll (args [len (args )- 1 ], "^" , "" )
444+ assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?body=mybody&title=mytitle" , url )
453445 })
454- defer restoreCmd ()
455446
456447 output , err := runCommand (http , true , `-w -t mytitle -b mybody` )
457448 if err != nil {
458449 t .Errorf ("error running command `issue create`: %v" , err )
459450 }
460451
461- if seenCmd == nil {
462- t .Fatal ("expected a command to run" )
463- }
464- url := strings .ReplaceAll (seenCmd .Args [len (seenCmd .Args )- 1 ], "^" , "" )
465- assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?body=mybody&title=mytitle" , url )
466452 assert .Equal (t , "" , output .String ())
467453 assert .Equal (t , "Opening github.com/OWNER/REPO/issues/new in your browser.\n " , output .Stderr ())
468454}
@@ -480,24 +466,20 @@ func TestIssueCreate_webTitleBodyAtMeAssignee(t *testing.T) {
480466 ` ),
481467 )
482468
483- var seenCmd * exec.Cmd
484- //nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
485- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
486- seenCmd = cmd
487- return & test.OutputStub {}
469+ cs , cmdTeardown := run .Stub ()
470+ defer cmdTeardown (t )
471+
472+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
473+ cs .Register (`https://github\.com` , 0 , "" , func (args []string ) {
474+ url := strings .ReplaceAll (args [len (args )- 1 ], "^" , "" )
475+ assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?assignees=MonaLisa&body=mybody&title=mytitle" , url )
488476 })
489- defer restoreCmd ()
490477
491478 output , err := runCommand (http , true , `-w -t mytitle -b mybody -a @me` )
492479 if err != nil {
493480 t .Errorf ("error running command `issue create`: %v" , err )
494481 }
495482
496- if seenCmd == nil {
497- t .Fatal ("expected a command to run" )
498- }
499- url := strings .ReplaceAll (seenCmd .Args [len (seenCmd .Args )- 1 ], "^" , "" )
500- assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?assignees=MonaLisa&body=mybody&title=mytitle" , url )
501483 assert .Equal (t , "" , output .String ())
502484 assert .Equal (t , "Opening github.com/OWNER/REPO/issues/new in your browser.\n " , output .Stderr ())
503485}
@@ -580,24 +562,20 @@ func TestIssueCreate_webProject(t *testing.T) {
580562 } } } }
581563 ` ))
582564
583- var seenCmd * exec.Cmd
584- //nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
585- restoreCmd := run .SetPrepareCmd (func (cmd * exec.Cmd ) run.Runnable {
586- seenCmd = cmd
587- return & test.OutputStub {}
565+ cs , cmdTeardown := run .Stub ()
566+ defer cmdTeardown (t )
567+
568+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
569+ cs .Register (`https://github\.com` , 0 , "" , func (args []string ) {
570+ url := strings .ReplaceAll (args [len (args )- 1 ], "^" , "" )
571+ assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?projects=OWNER%2FREPO%2F1&title=Title" , url )
588572 })
589- defer restoreCmd ()
590573
591574 output , err := runCommand (http , true , `-w -t Title -p Cleanup` )
592575 if err != nil {
593576 t .Errorf ("error running command `issue create`: %v" , err )
594577 }
595578
596- if seenCmd == nil {
597- t .Fatal ("expected a command to run" )
598- }
599- url := strings .ReplaceAll (seenCmd .Args [len (seenCmd .Args )- 1 ], "^" , "" )
600- assert .Equal (t , "https://github.com/OWNER/REPO/issues/new?projects=OWNER%2FREPO%2F1&title=Title" , url )
601579 assert .Equal (t , "" , output .String ())
602580 assert .Equal (t , "Opening github.com/OWNER/REPO/issues/new in your browser.\n " , output .Stderr ())
603581}
0 commit comments