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

Function TestRemoteGuessing

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

Source from the content-addressed store, hash-verified

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