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

Function TestRemoteGuessing

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

Source from the content-addressed store, hash-verified

2600}
2601
2602func TestRemoteGuessing(t *testing.T) {
2603 // Given git config does not provide the necessary info to determine a remote
2604 cs, cmdTeardown := run.Stub()
2605 defer cmdTeardown(t)
2606
2607 cs.Register(`git status --porcelain`, 0, "")
2608 cs.Register(`git config --get-regexp \^branch\\\..+\\\.\(remote\|merge\|pushremote\|gh-merge-base\)\$`, 0, "")
2609 cs.Register(`git rev-parse --symbolic-full-name feature@{push}`, 1, "")
2610 cs.Register("git config remote.pushDefault", 1, "")
2611 cs.Register("git config push.default", 1, "")
2612
2613 // And Given there is a remote on a SHA that matches the current HEAD
2614 cs.Register(`git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature`, 0, heredoc.Doc(`
2615 deadbeef HEAD
2616 deadb00f refs/remotes/upstream/feature
2617 deadbeef refs/remotes/origin/feature`))
2618
2619 // When the command is run
2620 reg := &httpmock.Registry{}
2621 reg.StubRepoInfoResponse("OWNER", "REPO", "master")
2622 defer reg.Verify(t)
2623
2624 reg.Register(
2625 httpmock.GraphQL(`mutation PullRequestCreate\b`),
2626 httpmock.GraphQLMutation(`
2627 { "data": { "createPullRequest": { "pullRequest": {
2628 "URL": "https://github.com/OWNER/REPO/pull/12"
2629 } } } }`, func(input map[string]any) {
2630 assert.Equal(t, "REPOID", input["repositoryId"].(string))
2631 assert.Equal(t, "master", input["baseRefName"].(string))
2632 assert.Equal(t, "OTHEROWNER:feature", input["headRefName"].(string))
2633 }))
2634
2635 ios, _, _, _ := iostreams.Test()
2636
2637 opts := CreateOptions{
2638 HttpClient: func() (*http.Client, error) {
2639 return &http.Client{Transport: reg}, nil
2640 },
2641 Config: func() (gh.Config, error) {
2642 return config.NewMockConfig(), nil
2643 },
2644 Browser: &browser.Stub{},
2645 IO: ios,
2646 Prompter: &prompter.PrompterMock{},
2647 GitClient: &git.Client{
2648 GhPath: "some/path/gh",
2649 GitPath: "some/path/git",
2650 },
2651 Finder: shared.NewMockFinder("feature", nil, nil),
2652 Remotes: func() (context.Remotes, error) {
2653 return context.Remotes{
2654 {
2655 Remote: &git.Remote{
2656 Name: "upstream",
2657 Resolved: "base",
2658 },
2659 Repo: ghrepo.New("OWNER", "REPO"),

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
StubRepoInfoResponseMethod · 0.95
VerifyMethod · 0.95
StubFunction · 0.92
GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
TestFunction · 0.92
NewMockConfigFunction · 0.92
NewMockFinderFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
createRunFunction · 0.70

Tested by

no test coverage detected