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