MCPcopy
hub / github.com/cli/cli / TestClientReadBranchConfig

Function TestClientReadBranchConfig

git/client_test.go:729–804  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

727}
728
729func TestClientReadBranchConfig(t *testing.T) {
730 tests := []struct {
731 name string
732 cmds mockedCommands
733 branch string
734 wantBranchConfig BranchConfig
735 wantError *GitError
736 }{
737 {
738 name: "when the git config has no (remote|merge|pushremote|gh-merge-base) keys, it should return an empty BranchConfig and no error",
739 cmds: mockedCommands{
740 `path/to/git config --get-regexp ^branch\.trunk\.(remote|merge|pushremote|gh-merge-base)$`: {
741 ExitStatus: 1,
742 },
743 },
744 branch: "trunk",
745 wantBranchConfig: BranchConfig{},
746 wantError: nil,
747 },
748 {
749 name: "when the git fails to read the config, it should return an empty BranchConfig and the error",
750 cmds: mockedCommands{
751 `path/to/git config --get-regexp ^branch\.trunk\.(remote|merge|pushremote|gh-merge-base)$`: {
752 ExitStatus: 2,
753 Stderr: "git error",
754 },
755 },
756 branch: "trunk",
757 wantBranchConfig: BranchConfig{},
758 wantError: &GitError{
759 ExitCode: 2,
760 Stderr: "git error",
761 },
762 },
763 {
764 name: "when the config is read, it should return the correct BranchConfig",
765 cmds: mockedCommands{
766 `path/to/git config --get-regexp ^branch\.trunk\.(remote|merge|pushremote|gh-merge-base)$`: {
767 Stdout: heredoc.Doc(`
768 branch.trunk.remote upstream
769 branch.trunk.merge refs/heads/trunk
770 branch.trunk.pushremote origin
771 branch.trunk.gh-merge-base gh-merge-base
772 `),
773 },
774 },
775 branch: "trunk",
776 wantBranchConfig: BranchConfig{
777 RemoteName: "upstream",
778 PushRemoteName: "origin",
779 MergeRef: "refs/heads/trunk",
780 MergeBase: "gh-merge-base",
781 },
782 wantError: nil,
783 },
784 }
785 for _, tt := range tests {
786 t.Run(tt.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

ReadBranchConfigMethod · 0.95
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected