diff --git a/pkg/cmd/gist/clone/clone_test.go b/pkg/cmd/gist/clone/clone_test.go index 8faf3d40c..f1e5b6d4d 100644 --- a/pkg/cmd/gist/clone/clone_test.go +++ b/pkg/cmd/gist/clone/clone_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/cli/cli/internal/config" + "github.com/cli/cli/internal/run" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/iostreams" @@ -88,13 +89,15 @@ func Test_GistClone(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { reg := &httpmock.Registry{} + defer reg.Verify(t) httpClient := &http.Client{Transport: reg} - cs, restore := test.InitCmdStubber() - defer restore() - - cs.Stub("") // git clone + cs, restore := run.Stub() + defer restore(t) + cs.Register(`git clone`, 0, "", func(s []string) { + assert.Equal(t, tt.want, strings.Join(s, " ")) + }) output, err := runCloneCommand(httpClient, tt.args) if err != nil { @@ -103,9 +106,6 @@ func Test_GistClone(t *testing.T) { assert.Equal(t, "", output.String()) assert.Equal(t, "", output.Stderr()) - assert.Equal(t, 1, cs.Count) - assert.Equal(t, tt.want, strings.Join(cs.Calls[0].Args, " ")) - reg.Verify(t) }) } } diff --git a/pkg/cmd/gist/create/create_test.go b/pkg/cmd/gist/create/create_test.go index 548abd743..70011d6e8 100644 --- a/pkg/cmd/gist/create/create_test.go +++ b/pkg/cmd/gist/create/create_test.go @@ -3,12 +3,12 @@ package create import ( "bytes" "encoding/json" - "github.com/cli/cli/test" "io/ioutil" "net/http" "strings" "testing" + "github.com/cli/cli/internal/run" "github.com/cli/cli/pkg/cmd/gist/shared" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/httpmock" @@ -291,11 +291,10 @@ func Test_createRun(t *testing.T) { io, stdin, stdout, stderr := iostreams.Test() tt.opts.IO = io - cs, cmdTeardown := test.InitCmdStubber() - defer cmdTeardown() - + cs, teardown := run.Stub() + defer teardown(t) if tt.opts.WebMode { - cs.Stub("") + cs.Register(`https://gist\.github\.com/aa5a315d61ae9438b18d$`, 0, "") } t.Run(tt.name, func(t *testing.T) { @@ -313,12 +312,6 @@ func Test_createRun(t *testing.T) { assert.Equal(t, tt.wantOut, stdout.String()) assert.Equal(t, tt.wantStderr, stderr.String()) assert.Equal(t, tt.wantParams, reqBody) - - if tt.opts.WebMode { - browserCall := cs.Calls[0].Args - assert.Equal(t, browserCall[len(browserCall)-1], "https://gist.github.com/aa5a315d61ae9438b18d") - } - reg.Verify(t) }) } diff --git a/pkg/cmd/pr/checks/checks_test.go b/pkg/cmd/pr/checks/checks_test.go index 64565a963..af4eb11e8 100644 --- a/pkg/cmd/pr/checks/checks_test.go +++ b/pkg/cmd/pr/checks/checks_test.go @@ -6,10 +6,10 @@ import ( "testing" "github.com/cli/cli/internal/ghrepo" + "github.com/cli/cli/internal/run" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/iostreams" - "github.com/cli/cli/test" "github.com/google/shlex" "github.com/stretchr/testify/assert" ) @@ -252,10 +252,9 @@ func TestChecksRun_web(t *testing.T) { opts.IO = io - cs, teardown := test.InitCmdStubber() - defer teardown() - - cs.Stub("") // browser open + cs, teardown := run.Stub() + defer teardown(t) + cs.Register(`https://github\.com/OWNER/REPO/pull/123/checks$`, 0, "") err := checksRun(opts) assert.NoError(t, err) diff --git a/pkg/cmd/pr/close/close_test.go b/pkg/cmd/pr/close/close_test.go index 3154b4e4b..0e5a1d942 100644 --- a/pkg/cmd/pr/close/close_test.go +++ b/pkg/cmd/pr/close/close_test.go @@ -9,6 +9,7 @@ import ( "github.com/cli/cli/internal/config" "github.com/cli/cli/internal/ghrepo" + "github.com/cli/cli/internal/run" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/iostreams" @@ -135,13 +136,11 @@ func TestPrClose_deleteBranch(t *testing.T) { httpmock.REST("DELETE", "repos/OWNER/REPO/git/refs/heads/blueberries"), httpmock.StringResponse(`{}`)) - cs, cmdTeardown := test.InitCmdStubber() - defer cmdTeardown() + cs, cmdTeardown := run.Stub() + defer cmdTeardown(t) - cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$ - cs.Stub("") // git rev-parse --verify blueberries` - cs.Stub("") // git branch -d - cs.Stub("") // git push origin --delete blueberries + cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") + cs.Register(`git branch -D blueberries`, 0, "") output, err := runCommand(http, true, `96 --delete-branch`) if err != nil { diff --git a/pkg/cmd/repo/view/view_test.go b/pkg/cmd/repo/view/view_test.go index 945fab965..005ec8515 100644 --- a/pkg/cmd/repo/view/view_test.go +++ b/pkg/cmd/repo/view/view_test.go @@ -8,10 +8,10 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/internal/ghrepo" + "github.com/cli/cli/internal/run" "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/iostreams" - "github.com/cli/cli/test" "github.com/google/shlex" "github.com/stretchr/testify/assert" ) @@ -132,18 +132,14 @@ func Test_RepoView_Web(t *testing.T) { t.Run(tt.name, func(t *testing.T) { io.SetStdoutTTY(tt.stdoutTTY) - cs, teardown := test.InitCmdStubber() - defer teardown() - - cs.Stub("") // browser open + cs, teardown := run.Stub() + defer teardown(t) + cs.Register(`https://github\.com/OWNER/REPO$`, 0, "") if err := viewRun(opts); err != nil { t.Errorf("viewRun() error = %v", err) } assert.Equal(t, "", stdout.String()) - assert.Equal(t, 1, len(cs.Calls)) - call := cs.Calls[0] - assert.Equal(t, "https://github.com/OWNER/REPO", call.Args[len(call.Args)-1]) assert.Equal(t, tt.wantStderr, stderr.String()) reg.Verify(t) })