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

Function TestClientPush

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

Source from the content-addressed store, hash-verified

1734}
1735
1736func TestClientPush(t *testing.T) {
1737 tests := []struct {
1738 name string
1739 mods []CommandModifier
1740 commands mockedCommands
1741 wantErrorMsg string
1742 }{
1743 {
1744 name: "push",
1745 commands: map[args]commandResult{
1746 `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential push --set-upstream origin trunk`: {
1747 ExitStatus: 0,
1748 },
1749 },
1750 },
1751 {
1752 name: "accepts command modifiers",
1753 mods: []CommandModifier{WithRepoDir("/path/to/repo")},
1754 commands: map[args]commandResult{
1755 `path/to/git -C /path/to/repo -c credential.helper= -c credential.helper=!"gh" auth git-credential push --set-upstream origin trunk`: {
1756 ExitStatus: 0,
1757 },
1758 },
1759 },
1760 {
1761 name: "git error on push",
1762 commands: map[args]commandResult{
1763 `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential push --set-upstream origin trunk`: {
1764 ExitStatus: 1,
1765 Stderr: "push error message",
1766 },
1767 },
1768 wantErrorMsg: "failed to run git: push error message",
1769 },
1770 }
1771
1772 for _, tt := range tests {
1773 t.Run(tt.name, func(t *testing.T) {
1774 cmdCtx := createMockedCommandContext(t, tt.commands)
1775 client := Client{
1776 GitPath: "path/to/git",
1777 commandContext: cmdCtx,
1778 }
1779 err := client.Push(context.Background(), "origin", "trunk", tt.mods...)
1780 if tt.wantErrorMsg == "" {
1781 require.NoError(t, err)
1782 } else {
1783 require.EqualError(t, err, tt.wantErrorMsg)
1784 }
1785 })
1786 }
1787}
1788
1789func TestClientClone(t *testing.T) {
1790 tests := []struct {

Callers

nothing calls this directly

Calls 4

PushMethod · 0.95
WithRepoDirFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected