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

Function TestClientRemoteURL

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

Source from the content-addressed store, hash-verified

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