🔥 last instance of mockOpenInBrowser
This commit is contained in:
parent
32e36d2fe0
commit
524fe0a69b
3 changed files with 16 additions and 21 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/github/gh-cli/test"
|
||||
"github.com/github/gh-cli/utils"
|
||||
)
|
||||
|
||||
func TestPRList(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue