MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestValidator_ValidateFile

Function TestValidator_ValidateFile

cmd/gosqlx/cmd/validator_test.go:29–123  ·  view source on GitHub ↗

TestValidator_ValidateFile tests single file validation

(t *testing.T)

Source from the content-addressed store, hash-verified

27
28// TestValidator_ValidateFile tests single file validation
29func TestValidator_ValidateFile(t *testing.T) {
30 tmpDir := t.TempDir()
31
32 tests := []struct {
33 name string
34 filename string
35 content string
36 expectValid bool
37 expectError bool
38 errorContains string
39 }{
40 {
41 name: "valid SQL file",
42 filename: "valid.sql",
43 content: "SELECT * FROM users WHERE active = true",
44 expectValid: true,
45 expectError: false,
46 },
47 {
48 name: "valid empty file",
49 filename: "empty.sql",
50 content: "",
51 expectValid: true,
52 expectError: false,
53 },
54 {
55 name: "invalid SQL - missing table name",
56 filename: "invalid.sql",
57 content: "SELECT * FROM",
58 expectValid: false,
59 expectError: true,
60 errorContains: "parsing failed",
61 },
62 {
63 name: "valid complex query with JOINs",
64 filename: "complex.sql",
65 content: "SELECT u.name, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.name",
66 expectValid: true,
67 expectError: false,
68 },
69 {
70 name: "valid window function",
71 filename: "window.sql",
72 content: "SELECT name, ROW_NUMBER() OVER (ORDER BY salary DESC) as rank FROM employees",
73 expectValid: true,
74 expectError: false,
75 },
76 {
77 name: "valid CTE",
78 filename: "cte.sql",
79 content: "WITH temp AS (SELECT id FROM users) SELECT * FROM temp",
80 expectValid: true,
81 expectError: false,
82 },
83 }
84
85 for _, tt := range tests {
86 t.Run(tt.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

validateFileMethod · 0.95
RunMethod · 0.80
NewValidatorFunction · 0.70
FatalfMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected