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

Function Test_createRun

pkg/cmd/pr/create/create_test.go:406–2076  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

404}
405
406func Test_createRun(t *testing.T) {
407 tests := []struct {
408 name string
409 setup func(*CreateOptions, *testing.T) func()
410 cmdStubs func(*run.CommandStubber)
411 promptStubs func(*prompter.PrompterMock)
412 httpStubs func(*httpmock.Registry, *testing.T)
413 expectedOutputs []string
414 expectedOut string
415 expectedErrOut string
416 expectedBrowse string
417 wantErr string
418 tty bool
419 customBranchConfig bool
420 // Defaults to WRITE, which can upload.
421 repoPermission string
422 }{
423 {
424 name: "nontty web",
425 setup: func(opts *CreateOptions, t *testing.T) func() {
426 opts.WebMode = true
427 opts.HeadBranch = "feature"
428 return func() {}
429 },
430 cmdStubs: func(cs *run.CommandStubber) {
431 cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "")
432 },
433 expectedBrowse: "https://github.com/OWNER/REPO/compare/master...feature?body=&expand=1",
434 },
435 {
436 name: "nontty",
437 httpStubs: func(reg *httpmock.Registry, t *testing.T) {
438 reg.Register(
439 httpmock.GraphQL(`mutation PullRequestCreate\b`),
440 httpmock.GraphQLMutation(`
441 { "data": { "createPullRequest": { "pullRequest": {
442 "URL": "https://github.com/OWNER/REPO/pull/12"
443 } } } }`,
444 func(input map[string]any) {
445 assert.Equal(t, "REPOID", input["repositoryId"])
446 assert.Equal(t, "my title", input["title"])
447 assert.Equal(t, "my body", input["body"])
448 assert.Equal(t, "master", input["baseRefName"])
449 assert.Equal(t, "feature", input["headRefName"])
450 }))
451 },
452 setup: func(opts *CreateOptions, t *testing.T) func() {
453 opts.TitleProvided = true
454 opts.BodyProvided = true
455 opts.Title = "my title"
456 opts.Body = "my body"
457 opts.HeadBranch = "feature"
458 return func() {}
459 },
460 expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
461 },
462 {
463 name: "same head and base branch should error",

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
StubRepoResponseMethod · 0.95
ExcludeMethod · 0.95
VerifyMethod · 0.95
BrowsedURLMethod · 0.95
StringMethod · 0.95
StderrMethod · 0.95
GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
StringResponseFunction · 0.92
NoSuchPromptErrFunction · 0.92

Tested by

no test coverage detected