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

Function TestSQLAnalyzer_IssueDetails

cmd/gosqlx/cmd/sql_analyzer_test.go:168–258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

166}
167
168func TestSQLAnalyzer_IssueDetails(t *testing.T) {
169 testCases := []struct {
170 name string
171 sql string
172 expectedIssueID string
173 checkFields func(t *testing.T, issue AnalysisIssue)
174 }{
175 {
176 name: "SELECT_STAR issue details",
177 sql: "SELECT * FROM users",
178 expectedIssueID: "SELECT_STAR",
179 checkFields: func(t *testing.T, issue AnalysisIssue) {
180 if issue.Category != IssueCategoryPerformance {
181 t.Errorf("Expected performance category, got %s", issue.Category)
182 }
183 if issue.Severity != IssueSeverityMedium {
184 t.Errorf("Expected medium severity, got %s", issue.Severity)
185 }
186 if !strings.Contains(issue.Description, "SELECT *") {
187 t.Error("Description should mention SELECT *")
188 }
189 if issue.Suggestion == "" {
190 t.Error("Suggestion should not be empty")
191 }
192 },
193 },
194 {
195 name: "FUNCTION_IN_WHERE issue details",
196 sql: "SELECT name FROM users WHERE UPPER(name) = 'TEST'",
197 expectedIssueID: "FUNCTION_IN_WHERE",
198 checkFields: func(t *testing.T, issue AnalysisIssue) {
199 if issue.Category != IssueCategoryPerformance {
200 t.Errorf("Expected performance category, got %s", issue.Category)
201 }
202 if issue.Severity != IssueSeverityMedium {
203 t.Errorf("Expected medium severity, got %s", issue.Severity)
204 }
205 if !strings.Contains(strings.ToLower(issue.Description), "function") {
206 t.Errorf("Description should mention function, got: %s", issue.Description)
207 }
208 },
209 },
210 }
211
212 for _, tc := range testCases {
213 t.Run(tc.name, func(t *testing.T) {
214 // Parse and analyze
215 tkz := tokenizer.GetTokenizer()
216 defer tokenizer.PutTokenizer(tkz)
217
218 tokens, err := tkz.Tokenize([]byte(tc.sql))
219 if err != nil {
220 t.Fatalf("Tokenization failed: %v", err)
221 }
222
223 p := parser.NewParser()
224 astObj := ast.NewAST()
225 defer ast.ReleaseAST(astObj)

Callers

nothing calls this directly

Calls 13

ParseFromModelTokensMethod · 0.95
AnalyzeMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
NewParserFunction · 0.92
NewASTFunction · 0.92
ReleaseASTFunction · 0.92
NewSQLAnalyzerFunction · 0.85
RunMethod · 0.80
TokenizeMethod · 0.80
ErrorfMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected