Skip to content

Commit 3fb4c48

Browse files
committed
modify tests
1 parent 54d92fa commit 3fb4c48

File tree

5 files changed

+91
-9
lines changed

5 files changed

+91
-9
lines changed

api/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func (c Client) REST(hostname string, method string, p string, body io.Reader, d
310310
if err != nil {
311311
return err
312312
}
313+
313314
err = json.Unmarshal(b, &data)
314315
if err != nil {
315316
return err

git/remote.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func AddRemote(name, u string) (*Remote, error) {
153153
}
154154

155155
func UpdateRemoteURL(name, u string) error {
156-
fmt.Println(name, u, "=====================name u==============")
157156
addCmd, err := GitCommand("remote", "set-url", name, u)
158157
if err != nil {
159158
return err

pkg/cmd/repo/fork/fork_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ func TestNewCmdFork(t *testing.T) {
132132
wantErr: true,
133133
errMsg: "unknown flag: --depth\nSeparate git clone flags with '--'.",
134134
},
135+
{
136+
name: "with fork name",
137+
cli: "--fork-name new-fork",
138+
wants: ForkOptions{
139+
Remote: false,
140+
RemoteName: "origin",
141+
ForkName: "new-fork",
142+
Rename: false,
143+
},
144+
},
135145
}
136146

137147
for _, tt := range tests {
@@ -529,6 +539,78 @@ func TestRepoFork(t *testing.T) {
529539
cs.Register(`git -C REPO remote add -f upstream https://github\.com/OWNER/REPO\.git`, 0, "")
530540
},
531541
},
542+
{
543+
name: "non tty repo arg with fork-name",
544+
opts: &ForkOptions{
545+
Repository: "someone/REPO",
546+
Clone: false,
547+
ForkName: "NEW_REPO",
548+
},
549+
tty: false,
550+
httpStubs: func(reg *httpmock.Registry) {
551+
forkResult := `{
552+
"node_id": "123",
553+
"name": "REPO",
554+
"clone_url": "https://github.com/OWNER/REPO.git",
555+
"created_at": "2011-01-26T19:01:12Z",
556+
"owner": {
557+
"login": "OWNER"
558+
}
559+
}`
560+
renameResult := `{
561+
"node_id": "1234",
562+
"name": "NEW_REPO",
563+
"clone_url": "https://github.com/OWNER/NEW_REPO.git",
564+
"created_at": "2012-01-26T19:01:12Z",
565+
"owner": {
566+
"login": "OWNER"
567+
}
568+
}`
569+
reg.Register(
570+
httpmock.REST("POST", "repos/someone/REPO/forks"),
571+
httpmock.StringResponse(forkResult))
572+
reg.Register(
573+
httpmock.REST("PATCH", "repos/OWNER/REPO"),
574+
httpmock.StringResponse(renameResult))
575+
},
576+
wantErrOut: "",
577+
},
578+
{
579+
name: "tty repo arg with fork-name",
580+
opts: &ForkOptions{
581+
Repository: "someone/REPO",
582+
Clone: false,
583+
ForkName: "NEW_REPO",
584+
},
585+
tty: true,
586+
httpStubs: func(reg *httpmock.Registry) {
587+
forkResult := `{
588+
"node_id": "123",
589+
"name": "REPO",
590+
"clone_url": "https://github.com/OWNER/REPO.git",
591+
"created_at": "2011-01-26T19:01:12Z",
592+
"owner": {
593+
"login": "OWNER"
594+
}
595+
}`
596+
renameResult := `{
597+
"node_id": "1234",
598+
"name": "NEW_REPO",
599+
"clone_url": "https://github.com/OWNER/NEW_REPO.git",
600+
"created_at": "2012-01-26T19:01:12Z",
601+
"owner": {
602+
"login": "OWNER"
603+
}
604+
}`
605+
reg.Register(
606+
httpmock.REST("POST", "repos/someone/REPO/forks"),
607+
httpmock.StringResponse(forkResult))
608+
reg.Register(
609+
httpmock.REST("PATCH", "repos/OWNER/REPO"),
610+
httpmock.StringResponse(renameResult))
611+
},
612+
wantErrOut: "✓ Created fork OWNER/NEW_REPO\n",
613+
},
532614
}
533615

534616
for _, tt := range tests {

pkg/cmd/repo/rename/rename.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ func renameRun(opts *RenameOptions) error {
122122
return err
123123
}
124124

125+
renamedRepo := ghrepo.New(newRepo.Owner.Login, newRepo.Name)
126+
125127
cs := opts.IO.ColorScheme()
126128
if opts.IO.IsStdoutTTY() {
127129
fmt.Fprintf(opts.IO.Out, "%s Renamed repository %s\n", cs.SuccessIcon(), ghrepo.FullName(newRepo))
128130
}
129131

130-
fmt.Println(opts.HasRepoOverride, "=========erpo override=============")
131-
132132
if opts.HasRepoOverride {
133133
return nil
134134
}
135135

136-
remote, err := updateRemote(currRepo, newRepo, opts)
136+
remote, err := updateRemote(currRepo, renamedRepo, opts)
137137
if err != nil {
138138
fmt.Fprintf(opts.IO.ErrOut, "%s Warning: unable to update remote %q: %v\n", cs.WarningIcon(), remote.Name, err)
139139
} else if opts.IO.IsStdoutTTY() {

pkg/cmd/repo/rename/rename_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestRenameRun(t *testing.T) {
122122
httpStubs: func(reg *httpmock.Registry) {
123123
reg.Register(
124124
httpmock.REST("PATCH", "repos/OWNER/REPO"),
125-
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
125+
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
126126
},
127127
execStubs: func(cs *run.CommandStubber) {
128128
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@@ -141,7 +141,7 @@ func TestRenameRun(t *testing.T) {
141141
httpStubs: func(reg *httpmock.Registry) {
142142
reg.Register(
143143
httpmock.REST("PATCH", "repos/OWNER/REPO"),
144-
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
144+
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
145145
},
146146
tty: true,
147147
},
@@ -154,7 +154,7 @@ func TestRenameRun(t *testing.T) {
154154
httpStubs: func(reg *httpmock.Registry) {
155155
reg.Register(
156156
httpmock.REST("PATCH", "repos/OWNER/REPO"),
157-
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
157+
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
158158
},
159159
execStubs: func(cs *run.CommandStubber) {
160160
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@@ -169,7 +169,7 @@ func TestRenameRun(t *testing.T) {
169169
httpStubs: func(reg *httpmock.Registry) {
170170
reg.Register(
171171
httpmock.REST("PATCH", "repos/OWNER/REPO"),
172-
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
172+
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
173173
},
174174
execStubs: func(cs *run.CommandStubber) {
175175
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")
@@ -189,7 +189,7 @@ func TestRenameRun(t *testing.T) {
189189
httpStubs: func(reg *httpmock.Registry) {
190190
reg.Register(
191191
httpmock.REST("PATCH", "repos/OWNER/REPO"),
192-
httpmock.StatusStringResponse(204, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
192+
httpmock.StatusStringResponse(200, `{"name":"NEW_REPO","owner":{"login":"OWNER"}}`))
193193
},
194194
execStubs: func(cs *run.CommandStubber) {
195195
cs.Register(`git remote set-url origin https://github.com/OWNER/NEW_REPO.git`, 0, "")

0 commit comments

Comments
 (0)