Skip to content

Commit 524fe0a

Browse files
committed
🔥 last instance of mockOpenInBrowser
1 parent 32e36d2 commit 524fe0a

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

command/issue_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package command
22

33
import (
44
"os"
5+
"os/exec"
56
"regexp"
67
"testing"
78

89
"github.com/github/gh-cli/test"
10+
"github.com/github/gh-cli/utils"
911
)
1012

1113
func TestIssueStatus(t *testing.T) {
@@ -43,8 +45,12 @@ func TestIssueView(t *testing.T) {
4345
defer jsonFile.Close()
4446
http.StubResponse(200, jsonFile)
4547

46-
teardown, callCount := mockOpenInBrowser()
47-
defer teardown()
48+
var seenCmd *exec.Cmd
49+
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
50+
seenCmd = cmd
51+
return &outputStub{}
52+
})
53+
defer restoreCmd()
4854

4955
output, err := test.RunCommand(RootCmd, "issue view 8")
5056
if err != nil {
@@ -55,7 +61,11 @@ func TestIssueView(t *testing.T) {
5561
t.Errorf("command output expected got an empty string")
5662
}
5763

58-
if *callCount != 1 {
59-
t.Errorf("OpenInBrowser should be called 1 time but was called %d time(s)", *callCount)
64+
if seenCmd == nil {
65+
t.Fatal("expected a command to run")
66+
}
67+
url := seenCmd.Args[len(seenCmd.Args)-1]
68+
if url != "https://github.com/OWNER/REPO/issues/8" {
69+
t.Errorf("got: %q", url)
6070
}
6171
}

command/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/github/gh-cli/test"
10+
"github.com/github/gh-cli/utils"
1011
)
1112

1213
func TestPRList(t *testing.T) {

command/testing.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package command
33
import (
44
"github.com/github/gh-cli/api"
55
"github.com/github/gh-cli/context"
6-
"github.com/github/gh-cli/utils"
76
)
87

98
func initBlankContext(repo, branch string) {
@@ -23,21 +22,6 @@ func initFakeHTTP() *api.FakeHTTP {
2322
return http
2423
}
2524

26-
func mockOpenInBrowser() (func(), *int) {
27-
callCount := 0
28-
originalOpenInBrowser := utils.OpenInBrowser
29-
teardown := func() {
30-
utils.OpenInBrowser = originalOpenInBrowser
31-
}
32-
33-
utils.OpenInBrowser = func(_ string) error {
34-
callCount++
35-
return nil
36-
}
37-
38-
return teardown, &callCount
39-
}
40-
4125
// outputStub implements a simple utils.Runnable
4226
type outputStub struct {
4327
output []byte
@@ -49,4 +33,4 @@ func (s outputStub) Output() ([]byte, error) {
4933

5034
func (s outputStub) Run() error {
5135
return nil
52-
}
36+
}

0 commit comments

Comments
 (0)