X Tutup
Skip to content

Commit c308f1c

Browse files
committed
Prevent further use of SetPrepareCmd and InitCmdStubber
1 parent 5531498 commit c308f1c

File tree

11 files changed

+56
-2
lines changed

11 files changed

+56
-2
lines changed

.golangci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
linters:
22
enable:
3-
gofmt
3+
- gofmt
4+
- nolintlint
5+
6+
issues:
7+
max-issues-per-linter: 0
8+
max-same-issues: 0

internal/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var PrepareCmd = func(cmd *exec.Cmd) Runnable {
2222
return &cmdWithStderr{cmd}
2323
}
2424

25-
// SetPrepareCmd overrides PrepareCmd and returns a func to revert it back
25+
// Deprecated: use Stub
2626
func SetPrepareCmd(fn func(*exec.Cmd) Runnable) func() {
2727
origPrepare := PrepareCmd
2828
PrepareCmd = func(cmd *exec.Cmd) Runnable {

pkg/cmd/issue/create/create_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func TestIssueCreate_continueInBrowser(t *testing.T) {
294294
})
295295

296296
var seenCmd *exec.Cmd
297+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
297298
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
298299
seenCmd = cmd
299300
return &test.OutputStub{}
@@ -422,6 +423,7 @@ func TestIssueCreate_web(t *testing.T) {
422423
defer http.Verify(t)
423424

424425
var seenCmd *exec.Cmd
426+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
425427
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
426428
seenCmd = cmd
427429
return &test.OutputStub{}
@@ -447,6 +449,7 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
447449
defer http.Verify(t)
448450

449451
var seenCmd *exec.Cmd
452+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
450453
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
451454
seenCmd = cmd
452455
return &test.OutputStub{}

pkg/cmd/issue/list/list_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ func TestIssueList_web(t *testing.T) {
218218
defer http.Verify(t)
219219

220220
var seenCmd *exec.Cmd
221+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
221222
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
222223
seenCmd = cmd
223224
return &test.OutputStub{}

pkg/cmd/issue/view/view_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func TestIssueView_web(t *testing.T) {
7474
)
7575

7676
var seenCmd *exec.Cmd
77+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
7778
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
7879
seenCmd = cmd
7980
return &test.OutputStub{}
@@ -110,6 +111,7 @@ func TestIssueView_web_numberArgWithHash(t *testing.T) {
110111
)
111112

112113
var seenCmd *exec.Cmd
114+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
113115
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
114116
seenCmd = cmd
115117
return &test.OutputStub{}
@@ -281,6 +283,7 @@ func TestIssueView_web_notFound(t *testing.T) {
281283
)
282284

283285
var seenCmd *exec.Cmd
286+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
284287
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
285288
seenCmd = cmd
286289
return &test.OutputStub{}
@@ -332,6 +335,7 @@ func TestIssueView_web_urlArg(t *testing.T) {
332335
)
333336

334337
var seenCmd *exec.Cmd
338+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
335339
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
336340
seenCmd = cmd
337341
return &test.OutputStub{}

pkg/cmd/pr/checkout/checkout_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestPRCheckout_sameRepo(t *testing.T) {
117117
`))
118118

119119
ranCommands := [][]string{}
120+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
120121
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
121122
switch strings.Join(cmd.Args, " ") {
122123
case "git show-ref --verify -- refs/heads/feature":
@@ -162,6 +163,7 @@ func TestPRCheckout_urlArg(t *testing.T) {
162163
`))
163164

164165
ranCommands := [][]string{}
166+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
165167
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
166168
switch strings.Join(cmd.Args, " ") {
167169
case "git show-ref --verify -- refs/heads/feature":
@@ -201,6 +203,7 @@ func TestPRCheckout_urlArg_differentBase(t *testing.T) {
201203
http.StubRepoInfoResponse("OWNER", "REPO", "master")
202204

203205
ranCommands := [][]string{}
206+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
204207
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
205208
switch strings.Join(cmd.Args, " ") {
206209
case "git show-ref --verify -- refs/heads/feature":
@@ -253,6 +256,7 @@ func TestPRCheckout_branchArg(t *testing.T) {
253256
`))
254257

255258
ranCommands := [][]string{}
259+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
256260
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
257261
switch strings.Join(cmd.Args, " ") {
258262
case "git show-ref --verify -- refs/heads/feature":
@@ -292,6 +296,7 @@ func TestPRCheckout_existingBranch(t *testing.T) {
292296
`))
293297

294298
ranCommands := [][]string{}
299+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
295300
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
296301
switch strings.Join(cmd.Args, " ") {
297302
case "git show-ref --verify -- refs/heads/feature":
@@ -344,6 +349,7 @@ func TestPRCheckout_differentRepo_remoteExists(t *testing.T) {
344349
`))
345350

346351
ranCommands := [][]string{}
352+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
347353
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
348354
switch strings.Join(cmd.Args, " ") {
349355
case "git show-ref --verify -- refs/heads/feature":
@@ -386,6 +392,7 @@ func TestPRCheckout_differentRepo(t *testing.T) {
386392
`))
387393

388394
ranCommands := [][]string{}
395+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
389396
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
390397
switch strings.Join(cmd.Args, " ") {
391398
case "git config branch.feature.merge":
@@ -428,6 +435,7 @@ func TestPRCheckout_differentRepo_existingBranch(t *testing.T) {
428435
`))
429436

430437
ranCommands := [][]string{}
438+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
431439
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
432440
switch strings.Join(cmd.Args, " ") {
433441
case "git config branch.feature.merge":
@@ -468,6 +476,7 @@ func TestPRCheckout_detachedHead(t *testing.T) {
468476
`))
469477

470478
ranCommands := [][]string{}
479+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
471480
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
472481
switch strings.Join(cmd.Args, " ") {
473482
case "git config branch.feature.merge":
@@ -508,6 +517,7 @@ func TestPRCheckout_differentRepo_currentBranch(t *testing.T) {
508517
`))
509518

510519
ranCommands := [][]string{}
520+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
511521
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
512522
switch strings.Join(cmd.Args, " ") {
513523
case "git config branch.feature.merge":
@@ -547,6 +557,7 @@ func TestPRCheckout_differentRepo_invalidBranchName(t *testing.T) {
547557
} } } }
548558
`))
549559

560+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
550561
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
551562
t.Errorf("unexpected external invocation: %v", cmd.Args)
552563
return &test.OutputStub{}
@@ -580,6 +591,7 @@ func TestPRCheckout_maintainerCanModify(t *testing.T) {
580591
`))
581592

582593
ranCommands := [][]string{}
594+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
583595
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
584596
switch strings.Join(cmd.Args, " ") {
585597
case "git config branch.feature.merge":
@@ -621,6 +633,7 @@ func TestPRCheckout_recurseSubmodules(t *testing.T) {
621633
`))
622634

623635
ranCommands := [][]string{}
636+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
624637
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
625638
switch strings.Join(cmd.Args, " ") {
626639
case "git show-ref --verify -- refs/heads/feature":

pkg/cmd/pr/create/create_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func TestPRCreate_nontty_web(t *testing.T) {
105105

106106
http.StubRepoInfoResponse("OWNER", "REPO", "master")
107107

108+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
108109
cs, cmdTeardown := test.InitCmdStubber()
109110
defer cmdTeardown()
110111

@@ -178,6 +179,7 @@ func TestPRCreate_recover(t *testing.T) {
178179
assert.Equal(t, "recovered body", input["body"].(string))
179180
}))
180181

182+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
181183
cs, cmdTeardown := test.InitCmdStubber()
182184
defer cmdTeardown()
183185

@@ -254,6 +256,7 @@ func TestPRCreate_nontty(t *testing.T) {
254256
}),
255257
)
256258

259+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
257260
cs, cmdTeardown := test.InitCmdStubber()
258261
defer cmdTeardown()
259262

@@ -296,6 +299,7 @@ func TestPRCreate(t *testing.T) {
296299
assert.Equal(t, "feature", input["headRefName"].(string))
297300
}))
298301

302+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
299303
cs, cmdTeardown := test.InitCmdStubber()
300304
defer cmdTeardown()
301305

@@ -351,6 +355,7 @@ func TestPRCreate_createFork(t *testing.T) {
351355
assert.Equal(t, "monalisa:feature", input["headRefName"].(string))
352356
}))
353357

358+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
354359
cs, cmdTeardown := test.InitCmdStubber()
355360
defer cmdTeardown()
356361

@@ -502,6 +507,7 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) {
502507
assert.Equal(t, "- commit 1\n- commit 0\n\nFixes a bug and Closes an issue", input["body"].(string))
503508
}))
504509

510+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
505511
cs, cmdTeardown := test.InitCmdStubber()
506512
defer cmdTeardown()
507513

@@ -635,6 +641,7 @@ func TestPRCreate_metadata(t *testing.T) {
635641
eq(t, inputs["union"], true)
636642
}))
637643

644+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
638645
cs, cmdTeardown := test.InitCmdStubber()
639646
defer cmdTeardown()
640647

@@ -662,6 +669,7 @@ func TestPRCreate_alreadyExists(t *testing.T) {
662669
] } } } }`),
663670
)
664671

672+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
665673
cs, cmdTeardown := test.InitCmdStubber()
666674
defer cmdTeardown()
667675

@@ -688,6 +696,7 @@ func TestPRCreate_web(t *testing.T) {
688696
httpmock.GraphQL(`query UserCurrent\b`),
689697
httpmock.StringResponse(`{"data": {"viewer": {"login": "OWNER"} } }`))
690698

699+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
691700
cs, cmdTeardown := test.InitCmdStubber()
692701
defer cmdTeardown()
693702

@@ -715,6 +724,7 @@ func TestPRCreate_web(t *testing.T) {
715724
}
716725

717726
func Test_determineTrackingBranch_empty(t *testing.T) {
727+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
718728
cs, cmdTeardown := test.InitCmdStubber()
719729
defer cmdTeardown()
720730

@@ -730,6 +740,7 @@ func Test_determineTrackingBranch_empty(t *testing.T) {
730740
}
731741

732742
func Test_determineTrackingBranch_noMatch(t *testing.T) {
743+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
733744
cs, cmdTeardown := test.InitCmdStubber()
734745
defer cmdTeardown()
735746

@@ -755,6 +766,7 @@ deadb00f refs/remotes/origin/feature`) // git show-ref --verify (ShowRefs)
755766
}
756767

757768
func Test_determineTrackingBranch_hasMatch(t *testing.T) {
769+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
758770
cs, cmdTeardown := test.InitCmdStubber()
759771
defer cmdTeardown()
760772

@@ -786,6 +798,7 @@ deadbeef refs/remotes/upstream/feature`) // git show-ref --verify (ShowRefs)
786798
}
787799

788800
func Test_determineTrackingBranch_respectTrackingConfig(t *testing.T) {
801+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
789802
cs, cmdTeardown := test.InitCmdStubber()
790803
defer cmdTeardown()
791804

pkg/cmd/pr/list/list_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func TestPRList_web(t *testing.T) {
207207
defer http.Verify(t)
208208

209209
var seenCmd *exec.Cmd
210+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
210211
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
211212
seenCmd = cmd
212213
return &test.OutputStub{}

pkg/cmd/pr/view/view_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ func TestPRView_web_currentBranch(t *testing.T) {
494494
http.Register(httpmock.GraphQL(`query PullRequestForBranch\b`), httpmock.FileResponse("./fixtures/prView.json"))
495495

496496
var seenCmd *exec.Cmd
497+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
497498
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
498499
switch strings.Join(cmd.Args, " ") {
499500
case `git config --get-regexp ^branch\.blueberries\.(remote|merge)$`:
@@ -528,6 +529,7 @@ func TestPRView_web_noResultsForBranch(t *testing.T) {
528529
http.Register(httpmock.GraphQL(`query PullRequestForBranch\b`), httpmock.FileResponse("./fixtures/prView_NoActiveBranch.json"))
529530

530531
var seenCmd *exec.Cmd
532+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
531533
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
532534
switch strings.Join(cmd.Args, " ") {
533535
case `git config --get-regexp ^branch\.blueberries\.(remote|merge)$`:
@@ -562,6 +564,7 @@ func TestPRView_web_numberArg(t *testing.T) {
562564
)
563565

564566
var seenCmd *exec.Cmd
567+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
565568
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
566569
seenCmd = cmd
567570
return &test.OutputStub{}
@@ -595,6 +598,7 @@ func TestPRView_web_numberArgWithHash(t *testing.T) {
595598
)
596599

597600
var seenCmd *exec.Cmd
601+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
598602
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
599603
seenCmd = cmd
600604
return &test.OutputStub{}
@@ -628,6 +632,7 @@ func TestPRView_web_urlArg(t *testing.T) {
628632
)
629633

630634
var seenCmd *exec.Cmd
635+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
631636
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
632637
seenCmd = cmd
633638
return &test.OutputStub{}
@@ -663,6 +668,7 @@ func TestPRView_web_branchArg(t *testing.T) {
663668
)
664669

665670
var seenCmd *exec.Cmd
671+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
666672
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
667673
seenCmd = cmd
668674
return &test.OutputStub{}
@@ -699,6 +705,7 @@ func TestPRView_web_branchWithOwnerArg(t *testing.T) {
699705
)
700706

701707
var seenCmd *exec.Cmd
708+
//nolint:staticcheck // SA1019 TODO: rewrite to use run.Stub
702709
restoreCmd := run.SetPrepareCmd(func(cmd *exec.Cmd) run.Runnable {
703710
seenCmd = cmd
704711
return &test.OutputStub{}

0 commit comments

Comments
 (0)
X Tutup