diff --git a/command/issue_test.go b/command/issue_test.go index 2181fcf37..4571bc43e 100644 --- a/command/issue_test.go +++ b/command/issue_test.go @@ -2,10 +2,12 @@ package command import ( "os" + "os/exec" "regexp" "testing" "github.com/github/gh-cli/test" + "github.com/github/gh-cli/utils" ) func TestIssueStatus(t *testing.T) { @@ -43,8 +45,12 @@ func TestIssueView(t *testing.T) { defer jsonFile.Close() http.StubResponse(200, jsonFile) - teardown, callCount := mockOpenInBrowser() - defer teardown() + var seenCmd *exec.Cmd + restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable { + seenCmd = cmd + return &outputStub{} + }) + defer restoreCmd() output, err := test.RunCommand(RootCmd, "issue view 8") if err != nil { @@ -55,7 +61,11 @@ func TestIssueView(t *testing.T) { t.Errorf("command output expected got an empty string") } - if *callCount != 1 { - t.Errorf("OpenInBrowser should be called 1 time but was called %d time(s)", *callCount) + if seenCmd == nil { + t.Fatal("expected a command to run") + } + url := seenCmd.Args[len(seenCmd.Args)-1] + if url != "https://github.com/OWNER/REPO/issues/8" { + t.Errorf("got: %q", url) } } diff --git a/command/pr_test.go b/command/pr_test.go index b51a3d26c..e4a4a7048 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/github/gh-cli/test" + "github.com/github/gh-cli/utils" ) func TestPRList(t *testing.T) { diff --git a/command/testing.go b/command/testing.go index 3b4717982..2e1cf9505 100644 --- a/command/testing.go +++ b/command/testing.go @@ -3,7 +3,6 @@ package command import ( "github.com/github/gh-cli/api" "github.com/github/gh-cli/context" - "github.com/github/gh-cli/utils" ) func initBlankContext(repo, branch string) { @@ -23,21 +22,6 @@ func initFakeHTTP() *api.FakeHTTP { return http } -func mockOpenInBrowser() (func(), *int) { - callCount := 0 - originalOpenInBrowser := utils.OpenInBrowser - teardown := func() { - utils.OpenInBrowser = originalOpenInBrowser - } - - utils.OpenInBrowser = func(_ string) error { - callCount++ - return nil - } - - return teardown, &callCount -} - // outputStub implements a simple utils.Runnable type outputStub struct { output []byte @@ -49,4 +33,4 @@ func (s outputStub) Output() ([]byte, error) { func (s outputStub) Run() error { return nil -} \ No newline at end of file +}