MCPcopy
hub / github.com/cli/cli / TestClientIsIgnored

Function TestClientIsIgnored

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

Source from the content-addressed store, hash-verified

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

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