File tree Expand file tree Collapse file tree 3 files changed +16
-21
lines changed
Expand file tree Collapse file tree 3 files changed +16
-21
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,12 @@ package command
22
33import (
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
1113func 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}
Original file line number Diff line number Diff line change 77 "testing"
88
99 "github.com/github/gh-cli/test"
10+ "github.com/github/gh-cli/utils"
1011)
1112
1213func TestPRList (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package command
33import (
44 "github.com/github/gh-cli/api"
55 "github.com/github/gh-cli/context"
6- "github.com/github/gh-cli/utils"
76)
87
98func 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
4226type outputStub struct {
4327 output []byte
@@ -49,4 +33,4 @@ func (s outputStub) Output() ([]byte, error) {
4933
5034func (s outputStub ) Run () error {
5135 return nil
52- }
36+ }
You can’t perform that action at this time.
0 commit comments