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

Function TestClientRemoteURL

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

Source from the content-addressed store, hash-verified

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