TestValidator_ExpandFileArgs tests file expansion (glob, directories)
(t *testing.T)
| 292 | |
| 293 | // TestValidator_ExpandFileArgs tests file expansion (glob, directories) |
| 294 | func TestValidator_ExpandFileArgs(t *testing.T) { |
| 295 | tmpDir := t.TempDir() |
| 296 | |
| 297 | // Create test directory structure |
| 298 | subDir := filepath.Join(tmpDir, "subdir") |
| 299 | os.Mkdir(subDir, 0755) |
| 300 | |
| 301 | // Create test files |
| 302 | testFiles := []string{ |
| 303 | filepath.Join(tmpDir, "query1.sql"), |
| 304 | filepath.Join(tmpDir, "query2.sql"), |
| 305 | filepath.Join(tmpDir, "script.txt"), |
| 306 | filepath.Join(subDir, "nested.sql"), |
| 307 | } |
| 308 | |
| 309 | for _, file := range testFiles { |
| 310 | os.WriteFile(file, []byte("SELECT 1"), 0644) |
| 311 | } |
| 312 | |
| 313 | tests := []struct { |
| 314 | name string |
| 315 | args []string |
| 316 | opts ValidatorOptions |
| 317 | expectFiles int |
| 318 | expectContains []string |
| 319 | }{ |
| 320 | { |
| 321 | name: "single file", |
| 322 | args: []string{filepath.Join(tmpDir, "query1.sql")}, |
| 323 | opts: ValidatorOptions{}, |
| 324 | expectFiles: 1, |
| 325 | expectContains: []string{"query1.sql"}, |
| 326 | }, |
| 327 | { |
| 328 | name: "glob pattern - *.sql", |
| 329 | args: []string{filepath.Join(tmpDir, "*.sql")}, |
| 330 | opts: ValidatorOptions{}, |
| 331 | expectFiles: 2, |
| 332 | expectContains: []string{"query1.sql", "query2.sql"}, |
| 333 | }, |
| 334 | { |
| 335 | name: "recursive directory", |
| 336 | args: []string{tmpDir}, |
| 337 | opts: ValidatorOptions{Recursive: true, Pattern: "*.sql"}, |
| 338 | expectFiles: 3, |
| 339 | expectContains: []string{"query1.sql", "query2.sql", "nested.sql"}, |
| 340 | }, |
| 341 | { |
| 342 | name: "multiple arguments", |
| 343 | args: []string{ |
| 344 | filepath.Join(tmpDir, "query1.sql"), |
| 345 | filepath.Join(tmpDir, "query2.sql"), |
| 346 | }, |
| 347 | opts: ValidatorOptions{}, |
| 348 | expectFiles: 2, |
| 349 | expectContains: []string{"query1.sql", "query2.sql"}, |
| 350 | }, |
| 351 | } |
nothing calls this directly
no test coverage detected