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

Function TestClientClone

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

Source from the content-addressed store, hash-verified

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