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

Function TestClientIsIgnored

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

Source from the content-addressed store, hash-verified

2225}
2226
2227func TestClientIsIgnored(t *testing.T) {
2228 tests := []struct {
2229 name string
2230 cmdExitStatus int
2231 cmdStdout string
2232 cmdStderr string
2233 wantCmdArgs string
2234 wantIgnored bool
2235 wantErr bool
2236 }{
2237 {
2238 name: "path is ignored",
2239 wantCmdArgs: "path/to/git check-ignore -q -- .github/skills",
2240 wantIgnored: true,
2241 },
2242 {
2243 name: "path is not ignored",
2244 cmdExitStatus: 1,
2245 wantCmdArgs: "path/to/git check-ignore -q -- .github/skills",
2246 wantIgnored: false,
2247 },
2248 {
2249 name: "fatal git error",
2250 cmdExitStatus: 128,
2251 cmdStderr: "fatal: not a git repository",
2252 wantCmdArgs: "path/to/git check-ignore -q -- .github/skills",
2253 wantIgnored: false,
2254 wantErr: true,
2255 },
2256 }
2257 for _, tt := range tests {
2258 t.Run(tt.name, func(t *testing.T) {
2259 cmd, cmdCtx := createCommandContext(t, tt.cmdExitStatus, tt.cmdStdout, tt.cmdStderr)
2260 client := Client{
2261 GitPath: "path/to/git",
2262 commandContext: cmdCtx,
2263 }
2264 ignored, err := client.IsIgnored(context.Background(), ".github/skills")
2265 assert.Equal(t, tt.wantCmdArgs, strings.Join(cmd.Args[3:], " "))
2266 assert.Equal(t, tt.wantIgnored, ignored)
2267 if tt.wantErr {
2268 assert.Error(t, err)
2269 } else {
2270 assert.NoError(t, err)
2271 }
2272 })
2273 }
2274
2275 // Covers the early return in IsIgnored when Command() itself fails
2276 // (e.g. git binary not resolvable).
2277 t.Run("returns error when git has a fatal error", func(t *testing.T) {
2278 t.Setenv("PATH", "")
2279 client := Client{}
2280 ignored, err := client.IsIgnored(context.Background(), ".github/skills")
2281 assert.False(t, ignored)
2282 assert.Error(t, err)
2283 })
2284}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected