Merge pull request #2801 from cli/cmd-stub-new
Deprecate `test` package
This commit is contained in:
commit
bdce08a793
35 changed files with 240 additions and 306 deletions
|
|
@ -1,3 +1,8 @@
|
|||
linters:
|
||||
enable:
|
||||
gofmt
|
||||
- gofmt
|
||||
- nolintlint
|
||||
|
||||
issues:
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
|
|
|
|||
15
git/git.go
15
git/git.go
|
|
@ -67,22 +67,21 @@ func CurrentBranch() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
stderr := bytes.Buffer{}
|
||||
refCmd.Stderr = &stderr
|
||||
|
||||
output, err := run.PrepareCmd(refCmd).Output()
|
||||
if err == nil {
|
||||
// Found the branch name
|
||||
return getBranchShortName(output), nil
|
||||
}
|
||||
|
||||
var cmdErr *run.CmdError
|
||||
if errors.As(err, &cmdErr) {
|
||||
if cmdErr.Stderr.Len() == 0 {
|
||||
// Detached head
|
||||
return "", ErrNotOnAnyBranch
|
||||
}
|
||||
if stderr.Len() == 0 {
|
||||
// Detached head
|
||||
return "", ErrNotOnAnyBranch
|
||||
}
|
||||
|
||||
// Unknown error
|
||||
return "", err
|
||||
return "", fmt.Errorf("%sgit: %s", stderr.String(), err)
|
||||
}
|
||||
|
||||
func listRemotes() ([]string, error) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cli/cli/internal/run"
|
||||
"github.com/cli/cli/test"
|
||||
)
|
||||
|
||||
func Test_UncommittedChangeCount(t *testing.T) {
|
||||
|
|
@ -21,20 +19,17 @@ func Test_UncommittedChangeCount(t *testing.T) {
|
|||
{Label: "untracked file", Expected: 2, Output: " M poem.txt\n?? new.txt"},
|
||||
}
|
||||
|
||||
teardown := run.SetPrepareCmd(func(*exec.Cmd) run.Runnable {
|
||||
return &test.OutputStub{}
|
||||
})
|
||||
defer teardown()
|
||||
|
||||
for _, v := range cases {
|
||||
_ = run.SetPrepareCmd(func(*exec.Cmd) run.Runnable {
|
||||
return &test.OutputStub{Out: []byte(v.Output)}
|
||||
})
|
||||
ucc, _ := UncommittedChangeCount()
|
||||
t.Run(v.Label, func(t *testing.T) {
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
cs.Register(`git status --porcelain`, 0, v.Output)
|
||||
|
||||
if ucc != v.Expected {
|
||||
t.Errorf("got unexpected ucc value: %d for case %s", ucc, v.Label)
|
||||
}
|
||||
ucc, _ := UncommittedChangeCount()
|
||||
if ucc != v.Expected {
|
||||
t.Errorf("UncommittedChangeCount() = %d, expected %d", ucc, v.Expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,59 +54,32 @@ func Test_CurrentBranch(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, v := range cases {
|
||||
cs, teardown := test.InitCmdStubber()
|
||||
cs.Stub(v.Stub)
|
||||
cs, teardown := run.Stub()
|
||||
cs.Register(`git symbolic-ref --quiet HEAD`, 0, v.Stub)
|
||||
|
||||
result, err := CurrentBranch()
|
||||
if err != nil {
|
||||
t.Errorf("got unexpected error: %w", err)
|
||||
}
|
||||
if len(cs.Calls) != 1 {
|
||||
t.Errorf("expected 1 git call, saw %d", len(cs.Calls))
|
||||
}
|
||||
if result != v.Expected {
|
||||
t.Errorf("unexpected branch name: %s instead of %s", result, v.Expected)
|
||||
}
|
||||
teardown()
|
||||
teardown(t)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_CurrentBranch_detached_head(t *testing.T) {
|
||||
cs, teardown := test.InitCmdStubber()
|
||||
defer teardown()
|
||||
|
||||
cs.StubError("")
|
||||
cs, teardown := run.Stub()
|
||||
defer teardown(t)
|
||||
cs.Register(`git symbolic-ref --quiet HEAD`, 1, "")
|
||||
|
||||
_, err := CurrentBranch()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
t.Fatal("expected an error, got nil")
|
||||
}
|
||||
if err != ErrNotOnAnyBranch {
|
||||
t.Errorf("got unexpected error: %s instead of %s", err, ErrNotOnAnyBranch)
|
||||
}
|
||||
if len(cs.Calls) != 1 {
|
||||
t.Errorf("expected 1 git call, saw %d", len(cs.Calls))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_CurrentBranch_unexpected_error(t *testing.T) {
|
||||
cs, teardown := test.InitCmdStubber()
|
||||
defer teardown()
|
||||
|
||||
cs.StubError("lol")
|
||||
|
||||
expectedError := "lol\nstub: lol"
|
||||
|
||||
_, err := CurrentBranch()
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != expectedError {
|
||||
t.Errorf("got unexpected error: %s instead of %s", err.Error(), expectedError)
|
||||
}
|
||||
if len(cs.Calls) != 1 {
|
||||
t.Errorf("expected 1 git call, saw %d", len(cs.Calls))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseExtraCloneArgs(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ var PrepareCmd = func(cmd *exec.Cmd) Runnable {
|
|||
return &cmdWithStderr{cmd}
|
||||
}
|
||||
|
||||
// SetPrepareCmd overrides PrepareCmd and returns a func to revert it back
|
||||
// Deprecated: use Stub
|
||||
func SetPrepareCmd(fn func(*exec.Cmd) Runnable) func() {
|
||||
origPrepare := PrepareCmd
|
||||
PrepareCmd = func(cmd *exec.Cmd) Runnable {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,9 @@ func TestAliasSet_empty_aliases(t *testing.T) {
|
|||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Added alias")
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), "")
|
||||
|
||||
expected := `aliases:
|
||||
|
|
@ -105,6 +107,7 @@ func TestAliasSet_existing_alias(t *testing.T) {
|
|||
output, err := runCommand(cfg, true, "co 'pr checkout -Rcool/repo'")
|
||||
require.NoError(t, err)
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Changed alias.*co.*from.*pr checkout.*to.*pr checkout -Rcool/repo")
|
||||
}
|
||||
|
||||
|
|
@ -117,8 +120,10 @@ func TestAliasSet_space_args(t *testing.T) {
|
|||
output, err := runCommand(cfg, true, `il 'issue list -l "cool story"'`)
|
||||
require.NoError(t, err)
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), `Adding alias for.*il.*issue list -l "cool story"`)
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, mainBuf.String(), `il: issue list -l "cool story"`)
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +158,9 @@ func TestAliasSet_arg_processing(t *testing.T) {
|
|||
t.Fatalf("got unexpected error running %s: %s", c.Cmd, err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), c.ExpectedOutputLine)
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, mainBuf.String(), c.ExpectedConfigLine)
|
||||
})
|
||||
}
|
||||
|
|
@ -175,6 +182,7 @@ aliases:
|
|||
diff: pr diff
|
||||
`
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Adding alias for.*diff.*pr diff", "Added alias.")
|
||||
assert.Equal(t, expected, mainBuf.String())
|
||||
}
|
||||
|
|
@ -196,6 +204,7 @@ func TestAliasSet_existing_aliases(t *testing.T) {
|
|||
view: pr view
|
||||
`
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Adding alias for.*view.*pr view", "Added alias.")
|
||||
assert.Equal(t, expected, mainBuf.String())
|
||||
|
||||
|
|
@ -221,6 +230,7 @@ func TestShellAlias_flag(t *testing.T) {
|
|||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Adding alias for.*igrep")
|
||||
|
||||
expected := `aliases:
|
||||
|
|
@ -238,6 +248,7 @@ func TestShellAlias_bang(t *testing.T) {
|
|||
output, err := runCommand(cfg, true, "igrep '!gh issue list | grep'")
|
||||
require.NoError(t, err)
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Adding alias for.*igrep")
|
||||
|
||||
expected := `aliases:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ func TestIssueCreate_continueInBrowser(t *testing.T) {
|
|||
})
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -410,6 +411,7 @@ func TestIssueCreate_web(t *testing.T) {
|
|||
defer http.Verify(t)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -435,6 +437,7 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
|
|||
defer http.Verify(t)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ func TestIssueList_nontty(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(),
|
||||
`1[\t]+number won[\t]+label[\t]+\d+`,
|
||||
`2[\t]+number too[\t]+label[\t]+\d+`,
|
||||
|
|
@ -210,6 +211,7 @@ func TestIssueList_web(t *testing.T) {
|
|||
defer http.Verify(t)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ func TestIssueView_web(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -108,6 +109,7 @@ func TestIssueView_web_numberArgWithHash(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -194,6 +196,7 @@ func TestIssueView_nontty_Preview(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -260,6 +263,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -279,6 +283,7 @@ func TestIssueView_web_notFound(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -330,6 +335,7 @@ func TestIssueView_web_urlArg(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -415,6 +421,7 @@ func TestIssueView_tty_Comments(t *testing.T) {
|
|||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -489,6 +496,7 @@ func TestIssueView_nontty_Comments(t *testing.T) {
|
|||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ func TestPRCheckout_sameRepo(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -154,6 +155,7 @@ func TestPRCheckout_urlArg(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -193,6 +195,7 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
|
|||
http.StubRepoInfoResponse("OWNER", "REPO", "master")
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -245,6 +248,7 @@ func TestPRCheckout_branchArg(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -284,6 +288,7 @@ func TestPRCheckout_existingBranch(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -336,6 +341,7 @@ func TestPRCheckout_differentRepo_remoteExists(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
@ -378,6 +384,7 @@ func TestPRCheckout_differentRepo(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git config branch.feature.merge":
|
||||
|
|
@ -420,6 +427,7 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git config branch.feature.merge":
|
||||
|
|
@ -460,6 +468,7 @@ func TestPRCheckout_detachedHead(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git config branch.feature.merge":
|
||||
|
|
@ -500,6 +509,7 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git config branch.feature.merge":
|
||||
|
|
@ -539,6 +549,7 @@ func TestPRCheckout_differentRepo_invalidBranchName(t *testing.T) {
|
|||
} } } }
|
||||
`))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
t.Errorf("unexpected external invocation: %v", cmd.Args)
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -570,6 +581,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git config branch.feature.merge":
|
||||
|
|
@ -611,6 +623,7 @@ func TestPRCheckout_recurseSubmodules(t *testing.T) {
|
|||
`))
|
||||
|
||||
ranCommands := [][]string{}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case "git show-ref --verify -- refs/heads/feature":
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,18 +136,17 @@ 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 {
|
||||
t.Fatalf("Got unexpected error running `pr close` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), `Closed pull request #96 \(The title of the PR\)`, `Deleted branch blueberries`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ func TestPRCreate_nontty_web(t *testing.T) {
|
|||
|
||||
http.StubRepoInfoResponse("OWNER", "REPO", "master")
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -166,6 +167,7 @@ func TestPRCreate_recover(t *testing.T) {
|
|||
assert.Equal(t, "recovered body", input["body"].(string))
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -242,6 +244,7 @@ func TestPRCreate_nontty(t *testing.T) {
|
|||
}),
|
||||
)
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -284,6 +287,7 @@ func TestPRCreate(t *testing.T) {
|
|||
assert.Equal(t, "feature", input["headRefName"].(string))
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -335,6 +339,7 @@ func TestPRCreate_NoMaintainerModify(t *testing.T) {
|
|||
assert.Equal(t, "feature", input["headRefName"].(string))
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -390,6 +395,7 @@ func TestPRCreate_createFork(t *testing.T) {
|
|||
assert.Equal(t, "monalisa:feature", input["headRefName"].(string))
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -541,6 +547,7 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) {
|
|||
assert.Equal(t, "- commit 1\n- commit 0\n\nFixes a bug and Closes an issue", input["body"].(string))
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -674,6 +681,7 @@ func TestPRCreate_metadata(t *testing.T) {
|
|||
assert.Equal(t, true, inputs["union"])
|
||||
}))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -701,6 +709,7 @@ func TestPRCreate_alreadyExists(t *testing.T) {
|
|||
] } } } }`),
|
||||
)
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -727,6 +736,7 @@ func TestPRCreate_web(t *testing.T) {
|
|||
httpmock.GraphQL(`query UserCurrent\b`),
|
||||
httpmock.StringResponse(`{"data": {"viewer": {"login": "OWNER"} } }`))
|
||||
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -754,6 +764,7 @@ func TestPRCreate_web(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_determineTrackingBranch_empty(t *testing.T) {
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -769,6 +780,7 @@ func Test_determineTrackingBranch_empty(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_determineTrackingBranch_noMatch(t *testing.T) {
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -794,6 +806,7 @@ deadb00f refs/remotes/origin/feature`) // git show-ref --verify (ShowRefs)
|
|||
}
|
||||
|
||||
func Test_determineTrackingBranch_hasMatch(t *testing.T) {
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
@ -825,6 +838,7 @@ deadbeef refs/remotes/upstream/feature`) // git show-ref --verify (ShowRefs)
|
|||
}
|
||||
|
||||
func Test_determineTrackingBranch_respectTrackingConfig(t *testing.T) {
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ func TestPRList_web(t *testing.T) {
|
|||
defer http.Verify(t)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
|
|||
|
|
@ -229,14 +229,8 @@ func TestPrMerge(t *testing.T) {
|
|||
assert.NotContains(t, input, "commitHeadline")
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("branch.blueberries.remote origin\nbranch.blueberries.merge refs/heads/blueberries") // git config --get-regexp ^branch\.master\.(remote|merge)
|
||||
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
|
||||
cs.Stub("") // git symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("")
|
||||
_, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
output, err := runCommand(http, "master", true, "pr merge 1 --merge")
|
||||
if err != nil {
|
||||
|
|
@ -272,14 +266,8 @@ func TestPrMerge_nontty(t *testing.T) {
|
|||
assert.NotContains(t, input, "commitHeadline")
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("branch.blueberries.remote origin\nbranch.blueberries.merge refs/heads/blueberries") // git config --get-regexp ^branch\.master\.(remote|merge)
|
||||
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
|
||||
cs.Stub("") // git symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("")
|
||||
_, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
output, err := runCommand(http, "master", false, "pr merge 1 --merge")
|
||||
if err != nil {
|
||||
|
|
@ -312,16 +300,14 @@ func TestPrMerge_withRepoFlag(t *testing.T) {
|
|||
assert.NotContains(t, input, "commitHeadline")
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
_, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
output, err := runCommand(http, "master", true, "pr merge 1 --merge -R OWNER/REPO")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `pr merge`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 0, len(cs.Calls))
|
||||
|
||||
r := regexp.MustCompile(`Merged pull request #1 \(The title of the PR\)`)
|
||||
|
||||
if !r.MatchString(output.Stderr()) {
|
||||
|
|
@ -347,20 +333,20 @@ func TestPrMerge_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 checkout master
|
||||
cs.Stub("") // git rev-parse --verify blueberries`
|
||||
cs.Stub("") // git branch -d
|
||||
cs.Stub("") // git push origin --delete blueberries
|
||||
cs.Register(`git config --get-regexp.+branch\\\.blueberries\\\.`, 0, "")
|
||||
cs.Register(`git checkout master`, 0, "")
|
||||
cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "")
|
||||
cs.Register(`git branch -D blueberries`, 0, "")
|
||||
|
||||
output, err := runCommand(http, "blueberries", true, `pr merge --merge --delete-branch`)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error running `pr merge` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), `Merged pull request #10 \(Blueberries are a good fruit\)`, `Deleted branch.*blueberries`)
|
||||
}
|
||||
|
||||
|
|
@ -382,19 +368,18 @@ func TestPrMerge_deleteNonCurrentBranch(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)
|
||||
|
||||
// We don't expect the default branch to be checked out, just that blueberries is deleted
|
||||
cs.Stub("") // git rev-parse --verify blueberries
|
||||
cs.Stub("") // git branch -d blueberries
|
||||
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, "master", true, `pr merge --merge --delete-branch blueberries`)
|
||||
if err != nil {
|
||||
t.Fatalf("Got unexpected error running `pr merge` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), `Merged pull request #10 \(Blueberries are a good fruit\)`, `Deleted branch.*blueberries`)
|
||||
}
|
||||
|
||||
|
|
@ -413,14 +398,10 @@ func TestPrMerge_noPrNumberGiven(t *testing.T) {
|
|||
assert.NotContains(t, input, "commitHeadline")
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
cs, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
cs.Stub("branch.blueberries.remote origin\nbranch.blueberries.merge refs/heads/blueberries") // git config --get-regexp ^branch\.master\.(remote|merge)
|
||||
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
|
||||
cs.Stub("") // git symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git branch -d
|
||||
cs.Register(`git config --get-regexp.+branch\\\.blueberries\\\.`, 0, "")
|
||||
|
||||
output, err := runCommand(http, "blueberries", true, "pr merge --merge")
|
||||
if err != nil {
|
||||
|
|
@ -456,13 +437,8 @@ func TestPrMerge_rebase(t *testing.T) {
|
|||
assert.NotContains(t, input, "commitHeadline")
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
|
||||
cs.Stub("") // git symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git branch -d
|
||||
_, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
output, err := runCommand(http, "master", true, "pr merge 2 --rebase")
|
||||
if err != nil {
|
||||
|
|
@ -498,19 +474,15 @@ func TestPrMerge_squash(t *testing.T) {
|
|||
assert.Equal(t, "The title of the PR (#3)", input["commitHeadline"].(string))
|
||||
}))
|
||||
|
||||
cs, cmdTeardown := test.InitCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git config --get-regexp ^branch\.blueberries\.(remote|merge)$
|
||||
cs.Stub("") // git symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git branch -d
|
||||
_, cmdTeardown := run.Stub()
|
||||
defer cmdTeardown(t)
|
||||
|
||||
output, err := runCommand(http, "master", true, "pr merge 3 --squash")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `pr merge`: %v", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Squashed and merged pull request #3")
|
||||
}
|
||||
|
||||
|
|
@ -550,6 +522,7 @@ func TestPrMerge_alreadyMerged(t *testing.T) {
|
|||
t.Fatalf("Got unexpected error running `pr merge` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "✔ Deleted branch blueberries and switched to branch master")
|
||||
}
|
||||
|
||||
|
|
@ -598,14 +571,13 @@ func TestPRMerge_interactive(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 symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git push origin --delete blueberries
|
||||
cs.Stub("") // git branch -d
|
||||
cs.Register(`git config --get-regexp.+branch\\\.blueberries\\\.`, 0, "")
|
||||
cs.Register(`git checkout master`, 0, "")
|
||||
cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "")
|
||||
cs.Register(`git branch -D blueberries`, 0, "")
|
||||
|
||||
as, surveyTeardown := prompt.InitAskStubber()
|
||||
defer surveyTeardown()
|
||||
|
|
@ -630,6 +602,7 @@ func TestPRMerge_interactive(t *testing.T) {
|
|||
t.Fatalf("Got unexpected error running `pr merge` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Merged pull request #3")
|
||||
}
|
||||
|
||||
|
|
@ -656,14 +629,13 @@ func TestPRMerge_interactiveWithDeleteBranch(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 symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git push origin --delete blueberries
|
||||
cs.Stub("") // git branch -d
|
||||
cs.Register(`git config --get-regexp.+branch\\\.blueberries\\\.`, 0, "")
|
||||
cs.Register(`git checkout master`, 0, "")
|
||||
cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "")
|
||||
cs.Register(`git branch -D blueberries`, 0, "")
|
||||
|
||||
as, surveyTeardown := prompt.InitAskStubber()
|
||||
defer surveyTeardown()
|
||||
|
|
@ -684,6 +656,7 @@ func TestPRMerge_interactiveWithDeleteBranch(t *testing.T) {
|
|||
t.Fatalf("Got unexpected error running `pr merge` %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Merged pull request #3", "Deleted branch blueberries and switched to branch master")
|
||||
}
|
||||
|
||||
|
|
@ -700,14 +673,10 @@ func TestPRMerge_interactiveCancelled(t *testing.T) {
|
|||
"number": 3
|
||||
}] } } } }`))
|
||||
|
||||
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 symbolic-ref --quiet --short HEAD
|
||||
cs.Stub("") // git checkout master
|
||||
cs.Stub("") // git push origin --delete blueberries
|
||||
cs.Stub("") // git branch -d
|
||||
cs.Register(`git config --get-regexp.+branch\\\.blueberries\\\.`, 0, "")
|
||||
|
||||
as, surveyTeardown := prompt.InitAskStubber()
|
||||
defer surveyTeardown()
|
||||
|
|
|
|||
|
|
@ -218,6 +218,7 @@ func TestPRReview_url_arg(t *testing.T) {
|
|||
t.Fatalf("error running pr review: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Approved pull request #123")
|
||||
}
|
||||
|
||||
|
|
@ -260,6 +261,7 @@ func TestPRReview_number_arg(t *testing.T) {
|
|||
t.Fatalf("error running pr review: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Approved pull request #123")
|
||||
}
|
||||
|
||||
|
|
@ -293,6 +295,7 @@ func TestPRReview_no_arg(t *testing.T) {
|
|||
t.Fatalf("error running pr review: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Reviewed pull request #123")
|
||||
}
|
||||
|
||||
|
|
@ -425,8 +428,10 @@ func TestPRReview_interactive(t *testing.T) {
|
|||
t.Fatalf("got unexpected error running pr review: %s", err)
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Approved pull request #123")
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(),
|
||||
"Got:",
|
||||
"cool.*story")
|
||||
|
|
@ -529,5 +534,6 @@ func TestPRReview_interactive_blank_approve(t *testing.T) {
|
|||
t.Errorf("did not expect to see body printed in %s", output.String())
|
||||
}
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(), "Approved pull request #123")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ func Test_PreserveInput(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
if tt.wantPreservation {
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, errOut.String(), tt.wantErrLine)
|
||||
preserved := &IssueMetadataState{}
|
||||
assert.NoError(t, json.Unmarshal(data, preserved))
|
||||
|
|
|
|||
|
|
@ -374,6 +374,7 @@ func TestPRView_Preview_nontty(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -552,6 +553,7 @@ func TestPRView_Preview(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tc.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -563,6 +565,7 @@ func TestPRView_web_currentBranch(t *testing.T) {
|
|||
http.Register(httpmock.GraphQL(`query PullRequestForBranch\b`), httpmock.FileResponse("./fixtures/prView.json"))
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case `git config --get-regexp ^branch\.blueberries\.(remote|merge)$`:
|
||||
|
|
@ -597,6 +600,7 @@ func TestPRView_web_noResultsForBranch(t *testing.T) {
|
|||
http.Register(httpmock.GraphQL(`query PullRequestForBranch\b`), httpmock.FileResponse("./fixtures/prView_NoActiveBranch.json"))
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
switch strings.Join(cmd.Args, " ") {
|
||||
case `git config --get-regexp ^branch\.blueberries\.(remote|merge)$`:
|
||||
|
|
@ -631,6 +635,7 @@ func TestPRView_web_numberArg(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -664,6 +669,7 @@ func TestPRView_web_numberArgWithHash(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -697,6 +703,7 @@ func TestPRView_web_urlArg(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -732,6 +739,7 @@ func TestPRView_web_branchArg(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -768,6 +776,7 @@ func TestPRView_web_branchWithOwnerArg(t *testing.T) {
|
|||
)
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -875,6 +884,7 @@ func TestPRView_tty_Comments(t *testing.T) {
|
|||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tt.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
@ -980,6 +990,7 @@ func TestPRView_nontty_Comments(t *testing.T) {
|
|||
}
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.String(), tt.expectedOutputs...)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ func Test_RepoClone(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query RepositoryInfo\b`),
|
||||
httpmock.StringResponse(`
|
||||
|
|
@ -197,10 +198,11 @@ func Test_RepoClone(t *testing.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 {
|
||||
|
|
@ -209,9 +211,6 @@ func Test_RepoClone(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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -254,6 +253,7 @@ func Test_RepoClone_hasParent(t *testing.T) {
|
|||
|
||||
func Test_RepoClone_withoutUsername(t *testing.T) {
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query UserCurrent\b`),
|
||||
httpmock.StringResponse(`
|
||||
|
|
@ -270,19 +270,12 @@ func Test_RepoClone_withoutUsername(t *testing.T) {
|
|||
}
|
||||
} } }
|
||||
`))
|
||||
reg.Register(
|
||||
httpmock.GraphQL(`query RepositoryFindParent\b`),
|
||||
httpmock.StringResponse(`
|
||||
{ "data": { "repository": {
|
||||
"parent": null
|
||||
} } }`))
|
||||
|
||||
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 https://github\.com/OWNER/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCloneCommand(httpClient, "REPO")
|
||||
if err != nil {
|
||||
|
|
@ -291,6 +284,4 @@ func Test_RepoClone_withoutUsername(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.String())
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
assert.Equal(t, 1, cs.Count)
|
||||
assert.Equal(t, "git clone https://github.com/OWNER/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ func TestRepoCreate(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -170,6 +171,7 @@ func TestRepoCreate_outsideGitWorkDir(t *testing.T) {
|
|||
{},
|
||||
{},
|
||||
}
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
if len(cmdOutputs) == 0 {
|
||||
t.Fatal("Too many calls to git command")
|
||||
|
|
@ -244,6 +246,7 @@ func TestRepoCreate_org(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -326,6 +329,7 @@ func TestRepoCreate_orgWithTeam(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -409,6 +413,7 @@ func TestRepoCreate_template(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
@ -489,6 +494,7 @@ func TestRepoCreate_withoutNameArg(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmd *exec.Cmd
|
||||
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
|
||||
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmd = cmd
|
||||
return &test.OutputStub{}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ package fork
|
|||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -83,21 +81,21 @@ func runCommand(httpClient *http.Client, remotes []*context.Remote, isTTY bool,
|
|||
func TestRepoFork_nontty(t *testing.T) {
|
||||
defer stubSince(2 * time.Second)()
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
_, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
output, err := runCommand(httpClient, nil, false, "")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 0, len(cs.Calls))
|
||||
assert.Equal(t, "", output.String())
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
reg.Verify(t)
|
||||
|
||||
}
|
||||
|
||||
func TestRepoFork_existing_remote_error(t *testing.T) {
|
||||
|
|
@ -128,26 +126,22 @@ func TestRepoFork_no_existing_remote(t *testing.T) {
|
|||
}
|
||||
defer stubSince(2 * time.Second)()
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Stub("") // git remote rename
|
||||
cs.Stub("") // git remote add
|
||||
cs.Register(`git remote add -f origin https://github\.com/someone/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCommand(httpClient, remotes, false, "--remote")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, len(cs.Calls))
|
||||
assert.Equal(t, "git remote add -f origin https://github.com/someone/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
reg.Verify(t)
|
||||
}
|
||||
|
||||
func TestRepoFork_in_parent_nontty(t *testing.T) {
|
||||
|
|
@ -156,20 +150,16 @@ func TestRepoFork_in_parent_nontty(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Stub("") // git remote rename
|
||||
cs.Stub("") // git remote add
|
||||
cs.Register(`git remote add -f fork https://github\.com/someone/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCommand(httpClient, nil, false, "--remote --remote-name=fork")
|
||||
if err != nil {
|
||||
t.Fatalf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, len(cs.Calls))
|
||||
assert.Equal(t, "git remote add -f fork https://github.com/someone/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
assert.Equal(t, "", output.Stderr())
|
||||
reg.Verify(t)
|
||||
|
|
@ -178,14 +168,15 @@ func TestRepoFork_in_parent_nontty(t *testing.T) {
|
|||
func TestRepoFork_outside_parent_nontty(t *testing.T) {
|
||||
defer stubSince(2 * time.Second)()
|
||||
reg := &httpmock.Registry{}
|
||||
reg.Verify(t)
|
||||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Stub("") // git clone
|
||||
cs.Stub("") // git remote add
|
||||
cs.Register(`git clone https://github.com/someone/REPO\.git`, 0, "")
|
||||
cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCommand(httpClient, nil, false, "--clone OWNER/REPO")
|
||||
if err != nil {
|
||||
|
|
@ -193,12 +184,8 @@ func TestRepoFork_outside_parent_nontty(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
assert.Equal(t, "git clone https://github.com/someone/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
assert.Equal(t, "git -C REPO remote add -f upstream https://github.com/OWNER/REPO.git", strings.Join(cs.Calls[1].Args, " "))
|
||||
|
||||
assert.Equal(t, output.Stderr(), "")
|
||||
reg.Verify(t)
|
||||
|
||||
}
|
||||
|
||||
func TestRepoFork_already_forked(t *testing.T) {
|
||||
|
|
@ -206,16 +193,14 @@ func TestRepoFork_already_forked(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
_, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
output, err := runCommand(httpClient, nil, true, "--remote=false")
|
||||
if err != nil {
|
||||
t.Errorf("got unexpected error: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 0, len(cs.Calls))
|
||||
|
||||
r := regexp.MustCompile(`someone/REPO.*already exists`)
|
||||
if !r.MatchString(output.Stderr()) {
|
||||
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output.Stderr())
|
||||
|
|
@ -257,8 +242,8 @@ func TestRepoFork_in_parent(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
_, restore := run.Stub()
|
||||
defer restore(t)
|
||||
defer stubSince(2 * time.Second)()
|
||||
|
||||
output, err := runCommand(httpClient, nil, true, "--remote=false")
|
||||
|
|
@ -266,7 +251,6 @@ func TestRepoFork_in_parent(t *testing.T) {
|
|||
t.Errorf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 0, len(cs.Calls))
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
r := regexp.MustCompile(`Created fork.*someone/REPO`)
|
||||
|
|
@ -321,23 +305,18 @@ func TestRepoFork_in_parent_yes(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmds []*exec.Cmd
|
||||
defer run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmds = append(seenCmds, cmd)
|
||||
return &test.OutputStub{}
|
||||
})()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Register(`git remote add -f fork https://github\.com/someone/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCommand(httpClient, nil, true, "--remote --remote-name=fork")
|
||||
if err != nil {
|
||||
t.Errorf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, len(seenCmds))
|
||||
expectedCmd := "git remote add -f fork https://github.com/someone/REPO.git"
|
||||
assert.Equal(t, expectedCmd, strings.Join(seenCmds[0].Args, " "))
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(),
|
||||
"Created fork.*someone/REPO",
|
||||
"Added remote.*fork")
|
||||
|
|
@ -350,11 +329,11 @@ func TestRepoFork_outside_yes(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Stub("") // git clone
|
||||
cs.Stub("") // git remote add
|
||||
cs.Register(`git clone https://github\.com/someone/REPO\.git`, 0, "")
|
||||
cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "")
|
||||
|
||||
output, err := runCommand(httpClient, nil, true, "--clone OWNER/REPO")
|
||||
if err != nil {
|
||||
|
|
@ -362,10 +341,7 @@ func TestRepoFork_outside_yes(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
assert.Equal(t, "git clone https://github.com/someone/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
assert.Equal(t, "git -C REPO remote add -f upstream https://github.com/OWNER/REPO.git", strings.Join(cs.Calls[1].Args, " "))
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(),
|
||||
"Created fork.*someone/REPO",
|
||||
"Cloned fork")
|
||||
|
|
@ -378,11 +354,11 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cs, restore := test.InitCmdStubber()
|
||||
defer restore()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Stub("") // git clone
|
||||
cs.Stub("") // git remote add
|
||||
cs.Register(`git clone https://github\.com/someone/REPO\.git`, 0, "")
|
||||
cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "")
|
||||
|
||||
defer prompt.StubConfirm(true)()
|
||||
|
||||
|
|
@ -392,10 +368,7 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
assert.Equal(t, "git clone https://github.com/someone/REPO.git", strings.Join(cs.Calls[0].Args, " "))
|
||||
assert.Equal(t, "git -C REPO remote add -f upstream https://github.com/OWNER/REPO.git", strings.Join(cs.Calls[1].Args, " "))
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(),
|
||||
"Created fork.*someone/REPO",
|
||||
"Cloned fork")
|
||||
|
|
@ -408,11 +381,8 @@ func TestRepoFork_outside_survey_no(t *testing.T) {
|
|||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
cmdRun := false
|
||||
defer run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
cmdRun = true
|
||||
return &test.OutputStub{}
|
||||
})()
|
||||
_, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
defer prompt.StubConfirm(false)()
|
||||
|
||||
|
|
@ -423,8 +393,6 @@ func TestRepoFork_outside_survey_no(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
assert.Equal(t, false, cmdRun)
|
||||
|
||||
r := regexp.MustCompile(`Created fork.*someone/REPO`)
|
||||
if !r.MatchString(output.Stderr()) {
|
||||
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
|
||||
|
|
@ -439,11 +407,10 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
|
|||
httpClient := &http.Client{Transport: reg}
|
||||
defer stubSince(2 * time.Second)()
|
||||
|
||||
var seenCmds []*exec.Cmd
|
||||
defer run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmds = append(seenCmds, cmd)
|
||||
return &test.OutputStub{}
|
||||
})()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Register(`git remote add -f fork https://github\.com/someone/REPO\.git`, 0, "")
|
||||
|
||||
defer prompt.StubConfirm(true)()
|
||||
|
||||
|
|
@ -452,12 +419,9 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
|
|||
t.Errorf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, len(seenCmds))
|
||||
expectedCmd := "git remote add -f fork https://github.com/someone/REPO.git"
|
||||
assert.Equal(t, expectedCmd, strings.Join(seenCmds[0].Args, " "))
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(),
|
||||
"Created fork.*someone/REPO",
|
||||
"Added remote.*fork")
|
||||
|
|
@ -466,15 +430,13 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
|
|||
|
||||
func TestRepoFork_in_parent_survey_no(t *testing.T) {
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
defer stubSince(2 * time.Second)()
|
||||
|
||||
cmdRun := false
|
||||
defer run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
cmdRun = true
|
||||
return &test.OutputStub{}
|
||||
})()
|
||||
_, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
defer prompt.StubConfirm(false)()
|
||||
|
||||
|
|
@ -485,14 +447,11 @@ func TestRepoFork_in_parent_survey_no(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
assert.Equal(t, false, cmdRun)
|
||||
|
||||
r := regexp.MustCompile(`Created fork.*someone/REPO`)
|
||||
if !r.MatchString(output.Stderr()) {
|
||||
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
|
||||
return
|
||||
}
|
||||
reg.Verify(t)
|
||||
}
|
||||
|
||||
func Test_RepoFork_gitFlags(t *testing.T) {
|
||||
|
|
@ -527,14 +486,14 @@ func Test_RepoFork_flagError(t *testing.T) {
|
|||
func TestRepoFork_in_parent_match_protocol(t *testing.T) {
|
||||
defer stubSince(2 * time.Second)()
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
defer reg.StubWithFixturePath(200, "./forkResult.json")()
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
|
||||
var seenCmds []*exec.Cmd
|
||||
defer run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
|
||||
seenCmds = append(seenCmds, cmd)
|
||||
return &test.OutputStub{}
|
||||
})()
|
||||
cs, restore := run.Stub()
|
||||
defer restore(t)
|
||||
|
||||
cs.Register(`git remote add -f fork git@github\.com:someone/REPO\.git`, 0, "")
|
||||
|
||||
remotes := []*context.Remote{
|
||||
{
|
||||
|
|
@ -550,16 +509,12 @@ func TestRepoFork_in_parent_match_protocol(t *testing.T) {
|
|||
t.Errorf("error running command `repo fork`: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, len(seenCmds))
|
||||
expectedCmd := "git remote add -f fork git@github.com:someone/REPO.git"
|
||||
assert.Equal(t, expectedCmd, strings.Join(seenCmds[0].Args, " "))
|
||||
|
||||
assert.Equal(t, "", output.String())
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, output.Stderr(),
|
||||
"Created fork.*someone/REPO",
|
||||
"Added remote.*fork")
|
||||
reg.Verify(t)
|
||||
}
|
||||
|
||||
func stubSince(d time.Duration) func() {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ func Test_listRun(t *testing.T) {
|
|||
|
||||
reg.Verify(t)
|
||||
|
||||
//nolint:staticcheck // prefer exact matchers over ExpectLines
|
||||
test.ExpectLines(t, stdout.String(), tt.wantOut...)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
1
test/fixtures/test.git/HEAD
vendored
1
test/fixtures/test.git/HEAD
vendored
|
|
@ -1 +0,0 @@
|
|||
ref: refs/heads/master
|
||||
6
test/fixtures/test.git/config
vendored
6
test/fixtures/test.git/config
vendored
|
|
@ -1,6 +0,0 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = false
|
||||
6
test/fixtures/test.git/info/exclude
vendored
6
test/fixtures/test.git/info/exclude
vendored
|
|
@ -1,6 +0,0 @@
|
|||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
x<01><>M
|
||||
Â0F]çseb~œ€ˆnÝx™¦cMi¨)^ß 7pó>xðñbÉ9UÐä7ub{ŽÖbgÙ´í‘ă#h8<68>÷<01>âµ>Ë×4o™áöÅ
|
||||
Çñ'ÊyÈœ¦],ùÚ„½Fkœ†-¢j¶U«üûW—¾‡*¯z¤IÔ)”;â
|
||||
Binary file not shown.
|
|
@ -1,3 +0,0 @@
|
|||
x<01><>K
|
||||
1D]η}¥3ι$qεBΟ<>dq&#^ίρs7UPΕ«XΖqhΠ/ZM Άw*<2A>cbc±G”3ΩΛ½ΦYηΠI<CEA0>βζk<CEB6> g
|
||||
6-U<>s4iΦ6‘³1χFΆμ#Y–,ό£<CF8C>K…ύ0<CF8D><30>i‚γG°Ύ|ƒ²=<3D>~Έ®b7 •λ$’b
KdD1§3eK<65>φΕn¨χο™Z<>C©σΥ<CF83>{Nm
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
test/fixtures/test.git/refs/heads/master
vendored
1
test/fixtures/test.git/refs/heads/master
vendored
|
|
@ -1 +0,0 @@
|
|||
9b5a719a3d76ac9dc2fa635d9b1f34fd73994c06
|
||||
|
|
@ -49,6 +49,7 @@ type CmdStubber struct {
|
|||
Calls []*exec.Cmd
|
||||
}
|
||||
|
||||
// Deprecated: use run.Stub
|
||||
func InitCmdStubber() (*CmdStubber, func()) {
|
||||
cs := CmdStubber{}
|
||||
teardown := run.SetPrepareCmd(createStubbedPrepareCmd(&cs))
|
||||
|
|
@ -90,6 +91,7 @@ type T interface {
|
|||
Errorf(string, ...interface{})
|
||||
}
|
||||
|
||||
// Deprecated: prefer exact matches for command output
|
||||
func ExpectLines(t T, output string, lines ...string) {
|
||||
t.Helper()
|
||||
var r *regexp.Regexp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue