X Tutup
Skip to content

Commit 39e6f41

Browse files
Merge pull request cli#856 from cli/a-better-runcommand
RFC: Make `RunCommand` less brittle
2 parents 1a1fc64 + 8c9fdc7 commit 39e6f41

File tree

8 files changed

+165
-159
lines changed

8 files changed

+165
-159
lines changed

command/completion_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func TestCompletion_bash(t *testing.T) {
9-
output, err := RunCommand(completionCmd, `completion`)
9+
output, err := RunCommand(`completion`)
1010
if err != nil {
1111
t.Fatal(err)
1212
}
@@ -17,7 +17,7 @@ func TestCompletion_bash(t *testing.T) {
1717
}
1818

1919
func TestCompletion_zsh(t *testing.T) {
20-
output, err := RunCommand(completionCmd, `completion -s zsh`)
20+
output, err := RunCommand(`completion -s zsh`)
2121
if err != nil {
2222
t.Fatal(err)
2323
}
@@ -28,7 +28,7 @@ func TestCompletion_zsh(t *testing.T) {
2828
}
2929

3030
func TestCompletion_fish(t *testing.T) {
31-
output, err := RunCommand(completionCmd, `completion -s fish`)
31+
output, err := RunCommand(`completion -s fish`)
3232
if err != nil {
3333
t.Fatal(err)
3434
}
@@ -39,7 +39,7 @@ func TestCompletion_fish(t *testing.T) {
3939
}
4040

4141
func TestCompletion_powerShell(t *testing.T) {
42-
output, err := RunCommand(completionCmd, `completion -s powershell`)
42+
output, err := RunCommand(`completion -s powershell`)
4343
if err != nil {
4444
t.Fatal(err)
4545
}
@@ -50,7 +50,7 @@ func TestCompletion_powerShell(t *testing.T) {
5050
}
5151

5252
func TestCompletion_unsupported(t *testing.T) {
53-
_, err := RunCommand(completionCmd, `completion -s csh`)
53+
_, err := RunCommand(`completion -s csh`)
5454
if err == nil || err.Error() != `unsupported shell type "csh"` {
5555
t.Fatal(err)
5656
}

command/config_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ editor: ed
1717
`
1818
initBlankContext(cfg, "OWNER/REPO", "master")
1919

20-
output, err := RunCommand(configGetCmd, "config get editor")
20+
output, err := RunCommand("config get editor")
2121
if err != nil {
2222
t.Fatalf("error running command `config get editor`: %v", err)
2323
}
@@ -27,7 +27,7 @@ editor: ed
2727

2828
func TestConfigGet_default(t *testing.T) {
2929
initBlankContext("", "OWNER/REPO", "master")
30-
output, err := RunCommand(configGetCmd, "config get git_protocol")
30+
output, err := RunCommand("config get git_protocol")
3131
if err != nil {
3232
t.Fatalf("error running command `config get git_protocol`: %v", err)
3333
}
@@ -38,7 +38,7 @@ func TestConfigGet_default(t *testing.T) {
3838
func TestConfigGet_not_found(t *testing.T) {
3939
initBlankContext("", "OWNER/REPO", "master")
4040

41-
output, err := RunCommand(configGetCmd, "config get missing")
41+
output, err := RunCommand("config get missing")
4242
if err != nil {
4343
t.Fatalf("error running command `config get missing`: %v", err)
4444
}
@@ -51,7 +51,7 @@ func TestConfigSet(t *testing.T) {
5151

5252
buf := bytes.NewBufferString("")
5353
defer config.StubWriteConfig(buf)()
54-
output, err := RunCommand(configSetCmd, "config set editor ed")
54+
output, err := RunCommand("config set editor ed")
5555
if err != nil {
5656
t.Fatalf("error running command `config set editor ed`: %v", err)
5757
}
@@ -82,7 +82,7 @@ editor: ed
8282
buf := bytes.NewBufferString("")
8383
defer config.StubWriteConfig(buf)()
8484

85-
output, err := RunCommand(configSetCmd, "config set editor vim")
85+
output, err := RunCommand("config set editor vim")
8686
if err != nil {
8787
t.Fatalf("error running command `config get editor`: %v", err)
8888
}
@@ -110,7 +110,7 @@ git_protocol: https
110110
`
111111
initBlankContext(cfg, "OWNER/REPO", "master")
112112

113-
output, err := RunCommand(configGetCmd, "config get -hgithub.com git_protocol")
113+
output, err := RunCommand("config get -hgithub.com git_protocol")
114114
if err != nil {
115115
t.Fatalf("error running command `config get editor`: %v", err)
116116
}
@@ -130,7 +130,7 @@ git_protocol: ssh
130130
`
131131
initBlankContext(cfg, "OWNER/REPO", "master")
132132

133-
output, err := RunCommand(configGetCmd, "config get -hgithub.com git_protocol")
133+
output, err := RunCommand("config get -hgithub.com git_protocol")
134134
if err != nil {
135135
t.Fatalf("error running command `config get -hgithub.com git_protocol`: %v", err)
136136
}
@@ -143,7 +143,7 @@ func TestConfigSetHost(t *testing.T) {
143143

144144
buf := bytes.NewBufferString("")
145145
defer config.StubWriteConfig(buf)()
146-
output, err := RunCommand(configSetCmd, "config set -hgithub.com git_protocol ssh")
146+
output, err := RunCommand("config set -hgithub.com git_protocol ssh")
147147
if err != nil {
148148
t.Fatalf("error running command `config set editor ed`: %v", err)
149149
}
@@ -174,7 +174,7 @@ hosts:
174174
buf := bytes.NewBufferString("")
175175
defer config.StubWriteConfig(buf)()
176176

177-
output, err := RunCommand(configSetCmd, "config set -hgithub.com git_protocol https")
177+
output, err := RunCommand("config set -hgithub.com git_protocol https")
178178
if err != nil {
179179
t.Fatalf("error running command `config get editor`: %v", err)
180180
}

command/issue_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestIssueStatus(t *testing.T) {
2424
defer jsonFile.Close()
2525
http.StubResponse(200, jsonFile)
2626

27-
output, err := RunCommand(issueStatusCmd, "issue status")
27+
output, err := RunCommand("issue status")
2828
if err != nil {
2929
t.Errorf("error running command `issue status`: %v", err)
3030
}
@@ -58,7 +58,7 @@ func TestIssueStatus_blankSlate(t *testing.T) {
5858
} } }
5959
`))
6060

61-
output, err := RunCommand(issueStatusCmd, "issue status")
61+
output, err := RunCommand("issue status")
6262
if err != nil {
6363
t.Errorf("error running command `issue status`: %v", err)
6464
}
@@ -92,7 +92,7 @@ func TestIssueStatus_disabledIssues(t *testing.T) {
9292
} } }
9393
`))
9494

95-
_, err := RunCommand(issueStatusCmd, "issue status")
95+
_, err := RunCommand("issue status")
9696
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
9797
t.Errorf("error running command `issue status`: %v", err)
9898
}
@@ -107,7 +107,7 @@ func TestIssueList(t *testing.T) {
107107
defer jsonFile.Close()
108108
http.StubResponse(200, jsonFile)
109109

110-
output, err := RunCommand(issueListCmd, "issue list")
110+
output, err := RunCommand("issue list")
111111
if err != nil {
112112
t.Errorf("error running command `issue list`: %v", err)
113113
}
@@ -143,7 +143,7 @@ func TestIssueList_withFlags(t *testing.T) {
143143
} } }
144144
`))
145145

146-
output, err := RunCommand(issueListCmd, "issue list -a probablyCher -l web,bug -s open -A foo")
146+
output, err := RunCommand("issue list -a probablyCher -l web,bug -s open -A foo")
147147
if err != nil {
148148
t.Errorf("error running command `issue list`: %v", err)
149149
}
@@ -183,7 +183,7 @@ func TestIssueList_nullAssigneeLabels(t *testing.T) {
183183
} } }
184184
`))
185185

186-
_, err := RunCommand(issueListCmd, "issue list")
186+
_, err := RunCommand("issue list")
187187
if err != nil {
188188
t.Errorf("error running command `issue list`: %v", err)
189189
}
@@ -211,7 +211,7 @@ func TestIssueList_disabledIssues(t *testing.T) {
211211
} } }
212212
`))
213213

214-
_, err := RunCommand(issueListCmd, "issue list")
214+
_, err := RunCommand("issue list")
215215
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
216216
t.Errorf("error running command `issue list`: %v", err)
217217
}
@@ -236,7 +236,7 @@ func TestIssueView_web(t *testing.T) {
236236
})
237237
defer restoreCmd()
238238

239-
output, err := RunCommand(issueViewCmd, "issue view -w 123")
239+
output, err := RunCommand("issue view -w 123")
240240
if err != nil {
241241
t.Errorf("error running command `issue view`: %v", err)
242242
}
@@ -270,7 +270,7 @@ func TestIssueView_web_numberArgWithHash(t *testing.T) {
270270
})
271271
defer restoreCmd()
272272

273-
output, err := RunCommand(issueViewCmd, "issue view -w \"#123\"")
273+
output, err := RunCommand("issue view -w \"#123\"")
274274
if err != nil {
275275
t.Errorf("error running command `issue view`: %v", err)
276276
}
@@ -350,7 +350,7 @@ func TestIssueView_Preview(t *testing.T) {
350350
defer jsonFile.Close()
351351
http.StubResponse(200, jsonFile)
352352

353-
output, err := RunCommand(issueViewCmd, tc.command)
353+
output, err := RunCommand(tc.command)
354354
if err != nil {
355355
t.Errorf("error running command `%v`: %v", tc.command, err)
356356
}
@@ -379,7 +379,7 @@ func TestIssueView_web_notFound(t *testing.T) {
379379
})
380380
defer restoreCmd()
381381

382-
_, err := RunCommand(issueViewCmd, "issue view -w 9999")
382+
_, err := RunCommand("issue view -w 9999")
383383
if err == nil || err.Error() != "graphql error: 'Could not resolve to an Issue with the number of 9999.'" {
384384
t.Errorf("error running command `issue view`: %v", err)
385385
}
@@ -401,7 +401,7 @@ func TestIssueView_disabledIssues(t *testing.T) {
401401
} } }
402402
`))
403403

404-
_, err := RunCommand(issueViewCmd, `issue view 6666`)
404+
_, err := RunCommand(`issue view 6666`)
405405
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
406406
t.Errorf("error running command `issue view`: %v", err)
407407
}
@@ -426,7 +426,7 @@ func TestIssueView_web_urlArg(t *testing.T) {
426426
})
427427
defer restoreCmd()
428428

429-
output, err := RunCommand(issueViewCmd, "issue view -w https://github.com/OWNER/REPO/issues/123")
429+
output, err := RunCommand("issue view -w https://github.com/OWNER/REPO/issues/123")
430430
if err != nil {
431431
t.Errorf("error running command `issue view`: %v", err)
432432
}
@@ -457,7 +457,7 @@ func TestIssueCreate(t *testing.T) {
457457
} } } }
458458
`))
459459

460-
output, err := RunCommand(issueCreateCmd, `issue create -t hello -b "cash rules everything around me"`)
460+
output, err := RunCommand(`issue create -t hello -b "cash rules everything around me"`)
461461
if err != nil {
462462
t.Errorf("error running command `issue create`: %v", err)
463463
}
@@ -493,7 +493,7 @@ func TestIssueCreate_disabledIssues(t *testing.T) {
493493
} } }
494494
`))
495495

496-
_, err := RunCommand(issueCreateCmd, `issue create -t heres -b johnny`)
496+
_, err := RunCommand(`issue create -t heres -b johnny`)
497497
if err == nil || err.Error() != "the 'OWNER/REPO' repository has disabled issues" {
498498
t.Errorf("error running command `issue create`: %v", err)
499499
}
@@ -511,7 +511,7 @@ func TestIssueCreate_web(t *testing.T) {
511511
})
512512
defer restoreCmd()
513513

514-
output, err := RunCommand(issueCreateCmd, `issue create --web`)
514+
output, err := RunCommand(`issue create --web`)
515515
if err != nil {
516516
t.Errorf("error running command `issue create`: %v", err)
517517
}
@@ -537,7 +537,7 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
537537
})
538538
defer restoreCmd()
539539

540-
output, err := RunCommand(issueCreateCmd, `issue create -w -t mytitle -b mybody`)
540+
output, err := RunCommand(`issue create -w -t mytitle -b mybody`)
541541
if err != nil {
542542
t.Errorf("error running command `issue create`: %v", err)
543543
}
@@ -695,7 +695,7 @@ func TestIssueClose(t *testing.T) {
695695

696696
http.StubResponse(200, bytes.NewBufferString(`{"id": "THE-ID"}`))
697697

698-
output, err := RunCommand(issueCloseCmd, "issue close 13")
698+
output, err := RunCommand("issue close 13")
699699
if err != nil {
700700
t.Fatalf("error running command `issue close`: %v", err)
701701
}
@@ -721,7 +721,7 @@ func TestIssueClose_alreadyClosed(t *testing.T) {
721721

722722
http.StubResponse(200, bytes.NewBufferString(`{"id": "THE-ID"}`))
723723

724-
output, err := RunCommand(issueCloseCmd, "issue close 13")
724+
output, err := RunCommand("issue close 13")
725725
if err != nil {
726726
t.Fatalf("error running command `issue close`: %v", err)
727727
}
@@ -744,7 +744,7 @@ func TestIssueClose_issuesDisabled(t *testing.T) {
744744
} } }
745745
`))
746746

747-
_, err := RunCommand(issueCloseCmd, "issue close 13")
747+
_, err := RunCommand("issue close 13")
748748
if err == nil {
749749
t.Fatalf("expected error when issues are disabled")
750750
}
@@ -768,7 +768,7 @@ func TestIssueReopen(t *testing.T) {
768768

769769
http.StubResponse(200, bytes.NewBufferString(`{"id": "THE-ID"}`))
770770

771-
output, err := RunCommand(issueReopenCmd, "issue reopen 2")
771+
output, err := RunCommand("issue reopen 2")
772772
if err != nil {
773773
t.Fatalf("error running command `issue reopen`: %v", err)
774774
}
@@ -794,7 +794,7 @@ func TestIssueReopen_alreadyOpen(t *testing.T) {
794794

795795
http.StubResponse(200, bytes.NewBufferString(`{"id": "THE-ID"}`))
796796

797-
output, err := RunCommand(issueReopenCmd, "issue reopen 2")
797+
output, err := RunCommand("issue reopen 2")
798798
if err != nil {
799799
t.Fatalf("error running command `issue reopen`: %v", err)
800800
}
@@ -817,7 +817,7 @@ func TestIssueReopen_issuesDisabled(t *testing.T) {
817817
} } }
818818
`))
819819

820-
_, err := RunCommand(issueReopenCmd, "issue reopen 2")
820+
_, err := RunCommand("issue reopen 2")
821821
if err == nil {
822822
t.Fatalf("expected error when issues are disabled")
823823
}

0 commit comments

Comments
 (0)
X Tutup