MCPcopy Create free account
hub / github.com/cli/cli / TestPrMerge

Function TestPrMerge

pkg/cmd/pr/merge/merge_test.go:315–354  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

313}
314
315func TestPrMerge(t *testing.T) {
316 http := initFakeHTTP()
317 defer http.Verify(t)
318
319 shared.StubFinderForRunCommandStyleTests(t,
320 "1",
321 &api.PullRequest{
322 ID: "THE-ID",
323 Number: 1,
324 State: "OPEN",
325 Title: "The title of the PR",
326 MergeStateStatus: "CLEAN",
327 },
328 baseRepo("OWNER", "REPO", "main"),
329 )
330
331 http.Register(
332 httpmock.GraphQL(`mutation PullRequestMerge\b`),
333 httpmock.GraphQLMutation(`{}`, func(input map[string]any) {
334 assert.Equal(t, "THE-ID", input["pullRequestId"].(string))
335 assert.Equal(t, "MERGE", input["mergeMethod"].(string))
336 assert.NotContains(t, input, "commitHeadline")
337 }),
338 )
339
340 cs, cmdTeardown := run.Stub()
341 defer cmdTeardown(t)
342 cs.Register(`git rev-parse --verify refs/heads/`, 0, "")
343
344 output, err := runCommand(http, nil, "main", true, "pr merge 1 --merge")
345 if err != nil {
346 t.Fatalf("error running command `pr merge`: %v", err)
347 }
348
349 r := regexp.MustCompile(`Merged pull request OWNER/REPO#1 \(The title of the PR\)`)
350
351 if !r.MatchString(output.Stderr()) {
352 t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr())
353 }
354}
355
356func TestPrMerge_blocked(t *testing.T) {
357 http := initFakeHTTP()

Callers

nothing calls this directly

Calls 11

GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
StubFunction · 0.92
baseRepoFunction · 0.85
EqualMethod · 0.80
StderrMethod · 0.80
initFakeHTTPFunction · 0.70
runCommandFunction · 0.70
VerifyMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected