loadSQLTestFiles loads all SQL files from testdata directory
(t *testing.T, rootPath string)
| 47 | |
| 48 | // loadSQLTestFiles loads all SQL files from testdata directory |
| 49 | func loadSQLTestFiles(t *testing.T, rootPath string) []SQLTestFile { |
| 50 | var files []SQLTestFile |
| 51 | |
| 52 | dialects := []string{"postgresql", "mysql", "mssql", "oracle", "real_world"} |
| 53 | |
| 54 | for _, dialect := range dialects { |
| 55 | dialectPath := filepath.Join(rootPath, "testdata", dialect) |
| 56 | |
| 57 | err := filepath.WalkDir(dialectPath, func(path string, d fs.DirEntry, err error) error { |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | if d.IsDir() || !strings.HasSuffix(path, ".sql") { |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | content, err := os.ReadFile(path) |
| 67 | if err != nil { |
| 68 | t.Logf("Warning: Could not read file %s: %v", path, err) |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | // Extract complexity from comment |
| 73 | complexity := "Medium" |
| 74 | contentStr := string(content) |
| 75 | if strings.Contains(contentStr, "Complexity: Simple") { |
| 76 | complexity = "Simple" |
| 77 | } else if strings.Contains(contentStr, "Complexity: Complex") { |
| 78 | complexity = "Complex" |
| 79 | } |
| 80 | |
| 81 | files = append(files, SQLTestFile{ |
| 82 | Path: path, |
| 83 | Dialect: dialect, |
| 84 | Name: filepath.Base(path), |
| 85 | Complexity: complexity, |
| 86 | Content: contentStr, |
| 87 | }) |
| 88 | |
| 89 | return nil |
| 90 | }) |
| 91 | |
| 92 | if err != nil { |
| 93 | t.Logf("Warning: Could not walk directory %s: %v", dialectPath, err) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return files |
| 98 | } |
| 99 | |
| 100 | // extractSQLStatement extracts the main SQL statement from a file (ignoring comments) |
| 101 | func extractSQLStatement(content string) string { |
no outgoing calls
no test coverage detected