MCPcopy
hub / github.com/cli/cli / Test_createRun

Function Test_createRun

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

Source from the content-addressed store, hash-verified

331}
332
333func Test_createRun(t *testing.T) {
334 tests := []struct {
335 name string
336 setup func(*CreateOptions, *testing.T) func()
337 cmdStubs func(*run.CommandStubber)
338 promptStubs func(*prompter.PrompterMock)
339 httpStubs func(*httpmock.Registry, *testing.T)
340 expectedOutputs []string
341 expectedOut string
342 expectedErrOut string
343 expectedBrowse string
344 wantErr string
345 tty bool
346 customBranchConfig bool
347 }{
348 {
349 name: "nontty web",
350 setup: func(opts *CreateOptions, t *testing.T) func() {
351 opts.WebMode = true
352 opts.HeadBranch = "feature"
353 return func() {}
354 },
355 cmdStubs: func(cs *run.CommandStubber) {
356 cs.Register(`git( .+)? log( .+)? origin/master\.\.\.feature`, 0, "")
357 },
358 expectedBrowse: "https://github.com/OWNER/REPO/compare/master...feature?body=&expand=1",
359 },
360 {
361 name: "nontty",
362 httpStubs: func(reg *httpmock.Registry, t *testing.T) {
363 reg.Register(
364 httpmock.GraphQL(`mutation PullRequestCreate\b`),
365 httpmock.GraphQLMutation(`
366 { "data": { "createPullRequest": { "pullRequest": {
367 "URL": "https://github.com/OWNER/REPO/pull/12"
368 } } } }`,
369 func(input map[string]interface{}) {
370 assert.Equal(t, "REPOID", input["repositoryId"])
371 assert.Equal(t, "my title", input["title"])
372 assert.Equal(t, "my body", input["body"])
373 assert.Equal(t, "master", input["baseRefName"])
374 assert.Equal(t, "feature", input["headRefName"])
375 }))
376 },
377 setup: func(opts *CreateOptions, t *testing.T) func() {
378 opts.TitleProvided = true
379 opts.BodyProvided = true
380 opts.Title = "my title"
381 opts.Body = "my body"
382 opts.HeadBranch = "feature"
383 return func() {}
384 },
385 expectedOut: "https://github.com/OWNER/REPO/pull/12\n",
386 },
387 {
388 name: "same head and base branch should error",
389 setup: func(opts *CreateOptions, t *testing.T) func() {
390 opts.TitleProvided = true

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
StubRepoResponseMethod · 0.95
StubRepoInfoResponseMethod · 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
IndexForFunction · 0.92

Tested by

no test coverage detected