X Tutup
Skip to content

Commit 877cbbb

Browse files
committed
use Stub instead of SetPrepareCmd in 'issue list' tests
1 parent c71dc87 commit 877cbbb

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

pkg/cmd/issue/list/list_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"encoding/json"
66
"io/ioutil"
77
"net/http"
8-
"os/exec"
98
"regexp"
9+
"strings"
1010
"testing"
1111

1212
"github.com/MakeNowJust/heredoc"
@@ -235,29 +235,21 @@ func TestIssueList_web(t *testing.T) {
235235
http := &httpmock.Registry{}
236236
defer http.Verify(t)
237237

238-
var seenCmd *exec.Cmd
239-
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
240-
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
241-
seenCmd = cmd
242-
return &test.OutputStub{}
238+
cs, cmdTeardown := run.Stub()
239+
defer cmdTeardown(t)
240+
241+
cs.Register(`https://github\.com`, 0, "", func(args []string) {
242+
url := strings.ReplaceAll(args[len(args)-1], "^", "")
243+
assert.Equal(t, "https://github.com/OWNER/REPO/issues?q=is%3Aissue+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+mentions%3Afrank+milestone%3Av1.1", url)
243244
})
244-
defer restoreCmd()
245245

246246
output, err := runCommand(http, true, "--web -a peter -A john -l bug -l docs -L 10 -s all --mention frank --milestone v1.1")
247247
if err != nil {
248248
t.Errorf("error running command `issue list` with `--web` flag: %v", err)
249249
}
250250

251-
expectedURL := "https://github.com/OWNER/REPO/issues?q=is%3Aissue+assignee%3Apeter+label%3Abug+label%3Adocs+author%3Ajohn+mentions%3Afrank+milestone%3Av1.1"
252-
253251
assert.Equal(t, "", output.String())
254252
assert.Equal(t, "Opening github.com/OWNER/REPO/issues in your browser.\n", output.Stderr())
255-
256-
if seenCmd == nil {
257-
t.Fatal("expected a command to run")
258-
}
259-
url := seenCmd.Args[len(seenCmd.Args)-1]
260-
assert.Equal(t, expectedURL, url)
261253
}
262254

263255
func TestIssueList_milestoneNotFound(t *testing.T) {

0 commit comments

Comments
 (0)
X Tutup