modify tests

This commit is contained in:
Gowtham Munukutla 2021-12-11 10:17:04 +05:30
parent 54d92facbf
commit 3fb4c481dc
5 changed files with 91 additions and 9 deletions

View file

@ -132,6 +132,16 @@ func TestNewCmdFork(t *testing.T) {
wantErr: true,
errMsg: "unknown flag: --depth\nSeparate git clone flags with '--'.",
},
{
name: "with fork name",
cli: "--fork-name new-fork",
wants: ForkOptions{
Remote: false,
RemoteName: "origin",
ForkName: "new-fork",
Rename: false,
},
},
}
for _, tt := range tests {
@ -529,6 +539,78 @@ func TestRepoFork(t *testing.T) {
cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "")
},
},
{
name: "non tty repo arg with fork-name",
opts: &ForkOptions{
Repository: "someone/REPO",
Clone: false,
ForkName: "NEW_REPO",
},
tty: false,
httpStubs: func(reg *httpmock.Registry) {
forkResult := `{
"node_id": "123",
"name": "REPO",
"clone_url": "https://github.com/OWNER/REPO.git",
"created_at": "2011-01-26T19:01:12Z",
"owner": {
"login": "OWNER"
}
}`
renameResult := `{
"node_id": "1234",
"name": "NEW_REPO",
"clone_url": "https://github.com/OWNER/NEW_REPO.git",
"created_at": "2012-01-26T19:01:12Z",
"owner": {
"login": "OWNER"
}
}`
reg.Register(
httpmock.REST("POST", "repos/someone/REPO/forks"),
httpmock.StringResponse(forkResult))
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StringResponse(renameResult))
},
wantErrOut: "",
},
{
name: "tty repo arg with fork-name",
opts: &ForkOptions{
Repository: "someone/REPO",
Clone: false,
ForkName: "NEW_REPO",
},
tty: true,
httpStubs: func(reg *httpmock.Registry) {
forkResult := `{
"node_id": "123",
"name": "REPO",
"clone_url": "https://github.com/OWNER/REPO.git",
"created_at": "2011-01-26T19:01:12Z",
"owner": {
"login": "OWNER"
}
}`
renameResult := `{
"node_id": "1234",
"name": "NEW_REPO",
"clone_url": "https://github.com/OWNER/NEW_REPO.git",
"created_at": "2012-01-26T19:01:12Z",
"owner": {
"login": "OWNER"
}
}`
reg.Register(
httpmock.REST("POST", "repos/someone/REPO/forks"),
httpmock.StringResponse(forkResult))
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StringResponse(renameResult))
},
wantErrOut: "✓ Created fork OWNER/NEW_REPO\n",
},
}
for _, tt := range tests {

View file

@ -122,18 +122,18 @@ func renameRun(opts *RenameOptions) error {
return err
}
renamedRepo := ghrepo.New(newRepo.Owner.Login, newRepo.Name)
cs := opts.IO.ColorScheme()
if opts.IO.IsStdoutTTY() {
fmt.Fprintf(opts.IO.Out, "%s Renamed repository %s\n", cs.SuccessIcon(), ghrepo.FullName(newRepo))
}
fmt.Println(opts.HasRepoOverride, "=========erpo override=============")
if opts.HasRepoOverride {
return nil
}
remote, err := updateRemote(currRepo, newRepo, opts)
remote, err := updateRemote(currRepo, renamedRepo, opts)
if err != nil {
fmt.Fprintf(opts.IO.ErrOut, "%s Warning: unable to update remote %q: %v\n", cs.WarningIcon(), remote.Name, err)
} else if opts.IO.IsStdoutTTY() {

View file

@ -122,7 +122,7 @@ func TestRenameRun(t *testing.T) {
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
},
execStubs: func(cs *run.CommandStubber) {
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@ -141,7 +141,7 @@ func TestRenameRun(t *testing.T) {
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
},
tty: true,
},
@ -154,7 +154,7 @@ func TestRenameRun(t *testing.T) {
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
},
execStubs: func(cs *run.CommandStubber) {
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@ -169,7 +169,7 @@ func TestRenameRun(t *testing.T) {
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
},
execStubs: func(cs *run.CommandStubber) {
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@ -189,7 +189,7 @@ func TestRenameRun(t *testing.T) {
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("PATCH", "repos/OWNER/REPO"),
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
},
execStubs: func(cs *run.CommandStubber) {
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")