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

Function TestClientPush

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

PushMethod · 0.95
WithRepoDirFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected