MCPcopy
hub / github.com/cli/cli / StubFinderForRunCommandStyleTests

Function StubFinderForRunCommandStyleTests

pkg/cmd/pr/shared/finder.go:78–93  ·  view source on GitHub ↗

StubFinderForRunCommandStyleTests is the NewMockFinder substitute to be used ONLY in runCommand-style tests.

(t *testing.T, selector string, pr *api.PullRequest, repo ghrepo.Interface)

Source from the content-addressed store, hash-verified

76
77// StubFinderForRunCommandStyleTests is the NewMockFinder substitute to be used ONLY in runCommand-style tests.
78func StubFinderForRunCommandStyleTests(t *testing.T, selector string, pr *api.PullRequest, repo ghrepo.Interface) *mockFinder {
79 // Create a new mock finder and override the "runCommandFinder" variable so that calls to
80 // NewFinder() will return this mock. This is a bad pattern, and a result of old style runCommand
81 // tests that would ideally be replaced. The reason we need to do this is that the runCommand style tests
82 // construct the cobra command via NewCmd* functions, and then Execute them directly, providing no opportunity
83 // to inject a test double unless it's on the factory, which finder never is, because only PR commands need it.
84 finder := NewMockFinder(selector, pr, repo)
85 finderForRunCommandStyleTests = finder
86
87 // Ensure that at the end of the test, we reset the "runCommandFinder" variable so that tests are isolated,
88 // at least if they are run sequentially.
89 t.Cleanup(func() {
90 finderForRunCommandStyleTests = nil
91 })
92 return finder
93}
94
95type FindOptions struct {
96 // Selector can be a number with optional `#` prefix, a branch name with optional `<owner>:` prefix, or

Callers 15

TestPrCloseFunction · 0.92
TestPrClose_withCommentFunction · 0.92
TestPrMergeFunction · 0.92
TestPrMerge_blockedFunction · 0.92
TestPrMerge_dirtyFunction · 0.92
TestPrMerge_nonttyFunction · 0.92

Calls 1

NewMockFinderFunction · 0.85

Tested by 15

TestPrCloseFunction · 0.74
TestPrClose_withCommentFunction · 0.74
TestPrMergeFunction · 0.74
TestPrMerge_blockedFunction · 0.74
TestPrMerge_dirtyFunction · 0.74
TestPrMerge_nonttyFunction · 0.74