MCPcopy
hub / github.com/cli/cli / TestClientRemoteURL

Function TestClientRemoteURL

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

Source from the content-addressed store, hash-verified

2166}
2167
2168func TestClientRemoteURL(t *testing.T) {
2169 tests := []struct {
2170 name string
2171 cmdExitStatus int
2172 cmdStdout string
2173 cmdStderr string
2174 wantCmdArgs string
2175 wantURL string
2176 wantErrorMsg string
2177 }{
2178 {
2179 name: "returns remote URL",
2180 cmdStdout: "https://github.com/monalisa/skills-repo.git\n",
2181 wantCmdArgs: "path/to/git remote get-url -- origin",
2182 wantURL: "https://github.com/monalisa/skills-repo.git",
2183 },
2184 {
2185 name: "git error",
2186 cmdExitStatus: 1,
2187 cmdStderr: "fatal: No such remote 'nonexistent'",
2188 wantCmdArgs: "path/to/git remote get-url -- nonexistent",
2189 wantErrorMsg: "failed to run git: fatal: No such remote 'nonexistent'",
2190 },
2191 }
2192 for _, tt := range tests {
2193 t.Run(tt.name, func(t *testing.T) {
2194 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
2195 client := Client{
2196 GitPath: "path/to/git",
2197 commandContext: cmdCtx,
2198 }
2199 remoteName := "origin"
2200 if tt.wantErrorMsg != "" {
2201 remoteName = "nonexistent"
2202 }
2203 url, err := client.RemoteURL(context.Background(), remoteName)
2204 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
2205 if tt.wantErrorMsg == "" {
2206 assert.NoError(t, err)
2207 assert.Equal(t, tt.wantURL, url)
2208 } else {
2209 assert.EqualError(t, err, tt.wantErrorMsg)
2210 }
2211 })
2212 }
2213
2214 // Covers the early return in RemoteURL when Command() itself fails.
2215 // (e.g. git binary not resolvable).
2216 t.Run("returns error when git has a fatal error", func(t *testing.T) {
2217 t.Setenv("PATH", "")
2218 client := Client{}
2219 _, err := client.RemoteURL(context.Background(), "origin")
2220 assert.Error(t, err)
2221 })
2222}
2223
2224func TestClientIsIgnored(t *testing.T) {
2225 tests := []struct {

Callers

nothing calls this directly

Calls 6

RemoteURLMethod · 0.95
createCommandContextFunction · 0.85
EqualMethod · 0.80
JoinMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected