MCPcopy
hub / github.com/cli/cli / TestClientClone

Function TestClientClone

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

CloneMethod · 0.95
WithRepoDirFunction · 0.85
createCommandContextFunction · 0.85
EqualMethod · 0.80
JoinMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected