"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/pr/checkout/checkout_test.go" between
gh-cli-1.10.3.tar.gz and gh-cli-1.11.0.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

checkout_test.go  (gh-cli-1.10.3):checkout_test.go  (gh-cli-1.11.0)
package checkout package checkout
import ( import (
"bytes" "bytes"
"errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
"testing" "testing"
"github.com/cli/cli/api" "github.com/cli/cli/api"
"github.com/cli/cli/context" "github.com/cli/cli/context"
"github.com/cli/cli/git" "github.com/cli/cli/git"
"github.com/cli/cli/internal/config" "github.com/cli/cli/internal/config"
"github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/internal/ghrepo"
skipping to change at line 62 skipping to change at line 63
return baseRepo, &api.PullRequest{ return baseRepo, &api.PullRequest{
Number: 123, Number: 123,
HeadRefName: headRefName, HeadRefName: headRefName,
HeadRepositoryOwner: api.Owner{Login: headRepo.RepoOwner()}, HeadRepositoryOwner: api.Owner{Login: headRepo.RepoOwner()},
HeadRepository: &api.PRRepository{Name: headRepo.RepoName()} , HeadRepository: &api.PRRepository{Name: headRepo.RepoName()} ,
IsCrossRepository: !ghrepo.IsSame(baseRepo, headRepo), IsCrossRepository: !ghrepo.IsSame(baseRepo, headRepo),
MaintainerCanModify: false, MaintainerCanModify: false,
} }
} }
func Test_checkoutRun(t *testing.T) {
tests := []struct {
name string
opts *CheckoutOptions
httpStubs func(*httpmock.Registry)
runStubs func(*run.CommandStubber)
remotes map[string]string
wantStdout string
wantStderr string
wantErr bool
}{
{
name: "fork repo was deleted",
opts: &CheckoutOptions{
SelectorArg: "123",
Finder: func() shared.PRFinder {
baseRepo, pr := stubPR("OWNER/REPO:master
", "hubot/REPO:feature")
pr.MaintainerCanModify = true
pr.HeadRepository = nil
finder := shared.NewMockFinder("123", pr,
baseRepo)
return finder
}(),
Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil
},
Branch: func() (string, error) {
return "main", nil
},
},
remotes: map[string]string{
"origin": "OWNER/REPO",
},
runStubs: func(cs *run.CommandStubber) {
cs.Register(`git fetch origin refs/pull/123/head:
feature`, 0, "")
cs.Register(`git config branch\.feature\.merge`,
1, "")
cs.Register(`git checkout feature`, 0, "")
cs.Register(`git config branch\.feature\.remote o
rigin`, 0, "")
cs.Register(`git config branch\.feature\.merge re
fs/pull/123/head`, 0, "")
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := tt.opts
io, _, stdout, stderr := iostreams.Test()
opts.IO = io
httpReg := &httpmock.Registry{}
defer httpReg.Verify(t)
if tt.httpStubs != nil {
tt.httpStubs(httpReg)
}
opts.HttpClient = func() (*http.Client, error) {
return &http.Client{Transport: httpReg}, nil
}
cmdStubs, cmdTeardown := run.Stub()
defer cmdTeardown(t)
if tt.runStubs != nil {
tt.runStubs(cmdStubs)
}
opts.Remotes = func() (context.Remotes, error) {
if len(tt.remotes) == 0 {
return nil, errors.New("no remotes")
}
var remotes context.Remotes
for name, repo := range tt.remotes {
r, err := ghrepo.FromFullName(repo)
if err != nil {
return remotes, err
}
remotes = append(remotes, &context.Remote
{
Remote: &git.Remote{Name: name},
Repo: r,
})
}
return remotes, nil
}
err := checkoutRun(opts)
if (err != nil) != tt.wantErr {
t.Errorf("want error: %v, got: %v", tt.wantErr, e
rr)
}
assert.Equal(t, tt.wantStdout, stdout.String())
assert.Equal(t, tt.wantStderr, stderr.String())
})
}
}
/** LEGACY TESTS **/
func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cl i string) (*test.CmdOut, error) { func runCommand(rt http.RoundTripper, remotes context.Remotes, branch string, cl i string) (*test.CmdOut, error) {
io, _, stdout, stderr := iostreams.Test() io, _, stdout, stderr := iostreams.Test()
factory := &cmdutil.Factory{ factory := &cmdutil.Factory{
IOStreams: io, IOStreams: io,
HttpClient: func() (*http.Client, error) { HttpClient: func() (*http.Client, error) {
return &http.Client{Transport: rt}, nil return &http.Client{Transport: rt}, nil
}, },
Config: func() (config.Config, error) { Config: func() (config.Config, error) {
return config.NewBlankConfig(), nil return config.NewBlankConfig(), nil
skipping to change at line 114 skipping to change at line 208
ErrBuf: stderr, ErrBuf: stderr,
}, err }, err
} }
func TestPRCheckout_sameRepo(t *testing.T) { func TestPRCheckout_sameRepo(t *testing.T) {
http := &httpmock.Registry{} http := &httpmock.Registry{}
defer http.Verify(t) defer http.Verify(t)
baseRepo, pr := stubPR("OWNER/REPO", "OWNER/REPO:feature") baseRepo, pr := stubPR("OWNER/REPO", "OWNER/REPO:feature")
finder := shared.RunCommandFinder("123", pr, baseRepo) finder := shared.RunCommandFinder("123", pr, baseRepo)
finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository"}) finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository", "maintainerCanModify"})
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git fetch origin \+refs/heads/feature:refs/remotes/origin/fe ature`, 0, "") cs.Register(`git fetch origin \+refs/heads/feature:refs/remotes/origin/fe ature`, 0, "")
cs.Register(`git show-ref --verify -- refs/heads/feature`, 1, "") cs.Register(`git show-ref --verify -- refs/heads/feature`, 1, "")
cs.Register(`git checkout -b feature --no-track origin/feature`, 0, "") cs.Register(`git checkout -b feature --no-track origin/feature`, 0, "")
cs.Register(`git config branch\.feature\.remote origin`, 0, "") cs.Register(`git config branch\.feature\.remote origin`, 0, "")
cs.Register(`git config branch\.feature\.merge refs/heads/feature`, 0, "" ) cs.Register(`git config branch\.feature\.merge refs/heads/feature`, 0, "" )
skipping to change at line 169 skipping to change at line 263
Remote: &git.Remote{Name: "robot-fork"}, Remote: &git.Remote{Name: "robot-fork"},
Repo: ghrepo.New("hubot", "REPO"), Repo: ghrepo.New("hubot", "REPO"),
}, },
} }
http := &httpmock.Registry{} http := &httpmock.Registry{}
defer http.Verify(t) defer http.Verify(t)
baseRepo, pr := stubPR("OWNER/REPO", "hubot/REPO:feature") baseRepo, pr := stubPR("OWNER/REPO", "hubot/REPO:feature")
finder := shared.RunCommandFinder("123", pr, baseRepo) finder := shared.RunCommandFinder("123", pr, baseRepo)
finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository"}) finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository", "maintainerCanModify"})
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git fetch robot-fork \+refs/heads/feature:refs/remotes/robot -fork/feature`, 0, "") cs.Register(`git fetch robot-fork \+refs/heads/feature:refs/remotes/robot -fork/feature`, 0, "")
cs.Register(`git show-ref --verify -- refs/heads/feature`, 1, "") cs.Register(`git show-ref --verify -- refs/heads/feature`, 1, "")
cs.Register(`git checkout -b feature --no-track robot-fork/feature`, 0, " ") cs.Register(`git checkout -b feature --no-track robot-fork/feature`, 0, " ")
cs.Register(`git config branch\.feature\.remote robot-fork`, 0, "") cs.Register(`git config branch\.feature\.remote robot-fork`, 0, "")
cs.Register(`git config branch\.feature\.merge refs/heads/feature`, 0, "" ) cs.Register(`git config branch\.feature\.merge refs/heads/feature`, 0, "" )
skipping to change at line 192 skipping to change at line 286
assert.Equal(t, "", output.String()) assert.Equal(t, "", output.String())
assert.Equal(t, "", output.Stderr()) assert.Equal(t, "", output.Stderr())
} }
func TestPRCheckout_differentRepo(t *testing.T) { func TestPRCheckout_differentRepo(t *testing.T) {
http := &httpmock.Registry{} http := &httpmock.Registry{}
defer http.Verify(t) defer http.Verify(t)
baseRepo, pr := stubPR("OWNER/REPO:master", "hubot/REPO:feature") baseRepo, pr := stubPR("OWNER/REPO:master", "hubot/REPO:feature")
finder := shared.RunCommandFinder("123", pr, baseRepo) finder := shared.RunCommandFinder("123", pr, baseRepo)
finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository"}) finder.ExpectFields([]string{"number", "headRefName", "headRepository", " headRepositoryOwner", "isCrossRepository", "maintainerCanModify"})
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git fetch origin refs/pull/123/head:feature`, 0, "") cs.Register(`git fetch origin refs/pull/123/head:feature`, 0, "")
cs.Register(`git config branch\.feature\.merge`, 1, "") cs.Register(`git config branch\.feature\.merge`, 1, "")
cs.Register(`git checkout feature`, 0, "") cs.Register(`git checkout feature`, 0, "")
cs.Register(`git config branch\.feature\.remote origin`, 0, "") cs.Register(`git config branch\.feature\.remote origin`, 0, "")
cs.Register(`git config branch\.feature\.merge refs/pull/123/head`, 0, "" ) cs.Register(`git config branch\.feature\.merge refs/pull/123/head`, 0, "" )
 End of changes. 5 change blocks. 
3 lines changed or deleted 105 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)