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

Function TestRemoteGuessing

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

Source from the content-addressed store, hash-verified

2641}
2642
2643func TestRemoteGuessing(t *testing.T) {
2644 // Given git config does not provide the necessary info to determine a remote
2645 cs, cmdTeardown := run.Stub()
2646 defer cmdTeardown(t)
2647
2648 cs.Register(`git status --porcelain`, 0, "")
2649 cs.Register(`git config --get-regexp \^branch\\\..+\\\.\(remote\|merge\|pushremote\|gh-merge-base\)\$`, 0, "")
2650 cs.Register(`git rev-parse --symbolic-full-name feature@{push}`, 1, "")
2651 cs.Register("git config remote.pushDefault", 1, "")
2652 cs.Register("git config push.default", 1, "")
2653
2654 // And Given there is a remote on a SHA that matches the current HEAD
2655 cs.Register(`git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature`, 0, heredoc.Doc(`
2656 deadbeef HEAD
2657 deadb00f refs/remotes/upstream/feature
2658 deadbeef refs/remotes/origin/feature`))
2659
2660 // When the command is run
2661 reg := &httpmock.Registry{}
2662 reg.StubRepoInfoResponse("OWNER", "REPO", "master")
2663 defer reg.Verify(t)
2664
2665 reg.Register(
2666 httpmock.GraphQL(`mutation PullRequestCreate\b`),
2667 httpmock.GraphQLMutation(`
2668 { "data": { "createPullRequest": { "pullRequest": {
2669 "URL": "https://github.com/OWNER/REPO/pull/12"
2670 } } } }`, func(input map[string]any) {
2671 assert.Equal(t, "REPOID", input["repositoryId"].(string))
2672 assert.Equal(t, "master", input["baseRefName"].(string))
2673 assert.Equal(t, "OTHEROWNER:feature", input["headRefName"].(string))
2674 }))
2675
2676 ios, _, _, _ := iostreams.Test()
2677
2678 opts := CreateOptions{
2679 HttpClient: func() (*http.Client, error) {
2680 return &http.Client{Transport: reg}, nil
2681 },
2682 Config: func() (gh.Config, error) {
2683 return config.NewMockConfig(), nil
2684 },
2685 Browser: &browser.Stub{},
2686 IO: ios,
2687 Prompter: &prompter.PrompterMock{},
2688 GitClient: &git.Client{
2689 GhPath: "some/path/gh",
2690 GitPath: "some/path/git",
2691 },
2692 Finder: shared.NewMockFinder("feature", nil, nil),
2693 Remotes: func() (context.Remotes, error) {
2694 return context.Remotes{
2695 {
2696 Remote: &git.Remote{
2697 Name: "upstream",
2698 Resolved: "base",
2699 },
2700 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