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

Function Test_createRun

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

Source from the content-addressed store, hash-verified

389}
390
391func Test_createRun(t *testing.T) {
392 tests := []struct {
393 name string
394 setup func(*CreateOptions, *testing.T) func()
395 cmdStubs func(*run.CommandStubber)
396 promptStubs func(*prompter.PrompterMock)
397 httpStubs func(*httpmock.Registry, *testing.T)
398 expectedOutputs []string
399 expectedOut string
400 expectedErrOut string
401 expectedBrowse string
402 wantErr string
403 tty bool
404 customBranchConfig bool
405 // Defaults to WRITE, which can upload.
406 repoPermission string
407 }{
408 {
409 name: "nontty web",
410 setup: func(opts *CreateOptions, t *testing.T) func() {
411 opts.WebMode = true
412 opts.HeadBranch = "feature"
413 return func() {}
414 },
415 cmdStubs: func(cs *run.CommandStubber) {
416 cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "")
417 },
418 expectedBrowse: "https://github.com/OWNER/REPO/compare/master...feature?body=&expand=1",
419 },
420 {
421 name: "nontty",
422 httpStubs: func(reg *httpmock.Registry, t *testing.T) {
423 reg.Register(
424 httpmock.GraphQL(`mutation PullRequestCreate\b`),
425 httpmock.GraphQLMutation(`
426 { "data": { "createPullRequest": { "pullRequest": {
427 "URL": "https://github.com/OWNER/REPO/pull/12"
428 } } } }`,
429 func(input map[string]any) {
430 assert.Equal(t, "REPOID", input["repositoryId"])
431 assert.Equal(t, "my title", input["title"])
432 assert.Equal(t, "my body", input["body"])
433 assert.Equal(t, "master", input["baseRefName"])
434 assert.Equal(t, "feature", input["headRefName"])
435 }))
436 },
437 setup: func(opts *CreateOptions, t *testing.T) func() {
438 opts.TitleProvided = true
439 opts.BodyProvided = true
440 opts.Title = "my title"
441 opts.Body = "my body"
442 opts.HeadBranch = "feature"
443 return func() {}
444 },
445 expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
446 },
447 {
448 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