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