(t *testing.T)
| 1788 | } |
| 1789 | |
| 1790 | func TestClientClone(t *testing.T) { |
| 1791 | tests := []struct { |
| 1792 | name string |
| 1793 | args []string |
| 1794 | mods []CommandModifier |
| 1795 | cmdExitStatus int |
| 1796 | cmdStdout string |
| 1797 | cmdStderr string |
| 1798 | wantCmdArgs string |
| 1799 | wantTarget string |
| 1800 | wantErrorMsg string |
| 1801 | }{ |
| 1802 | { |
| 1803 | name: "clone", |
| 1804 | args: []string{}, |
| 1805 | wantCmdArgs: `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential clone https://github.com/cli/cli`, |
| 1806 | wantTarget: "cli", |
| 1807 | }, |
| 1808 | { |
| 1809 | name: "accepts command modifiers", |
| 1810 | args: []string{}, |
| 1811 | mods: []CommandModifier{WithRepoDir("/path/to/repo")}, |
| 1812 | wantCmdArgs: `path/to/git -C /path/to/repo -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential clone https://github.com/cli/cli`, |
| 1813 | wantTarget: "cli", |
| 1814 | }, |
| 1815 | { |
| 1816 | name: "git error", |
| 1817 | args: []string{}, |
| 1818 | cmdExitStatus: 1, |
| 1819 | cmdStderr: "git error message", |
| 1820 | wantCmdArgs: `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential clone https://github.com/cli/cli`, |
| 1821 | wantErrorMsg: "failed to run git: git error message", |
| 1822 | }, |
| 1823 | { |
| 1824 | name: "bare clone", |
| 1825 | args: []string{"--bare"}, |
| 1826 | wantCmdArgs: `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential clone --bare https://github.com/cli/cli`, |
| 1827 | wantTarget: "cli.git", |
| 1828 | }, |
| 1829 | { |
| 1830 | name: "bare clone with explicit target", |
| 1831 | args: []string{"cli-bare", "--bare"}, |
| 1832 | wantCmdArgs: `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential clone --bare https://github.com/cli/cli cli-bare`, |
| 1833 | wantTarget: "cli-bare", |
| 1834 | }, |
| 1835 | } |
| 1836 | for _, tt := range tests { |
| 1837 | t.Run(tt.name, func(t *testing.T) { |
| 1838 | cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr) |
| 1839 | client := Client{ |
| 1840 | GitPath: "path/to/git", |
| 1841 | commandContext: cmdCtx, |
| 1842 | } |
| 1843 | target, err := client.Clone(context.Background(), "https://github.com/cli/cli", tt.args, tt.mods...) |
| 1844 | assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " ")) |
| 1845 | if tt.wantErrorMsg == "" { |
| 1846 | assert.NoError(t, err) |
| 1847 | } else { |
nothing calls this directly
no test coverage detected