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

Function TestSQLAnalyzer_AnalyzeFixtures

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

Source from the content-addressed store, hash-verified

63}
64
65func TestSQLAnalyzer_AnalyzeFixtures(t *testing.T) {
66 for testName, fixture := range testSQLFixtures {
67 t.Run(testName, func(t *testing.T) {
68 // Parse the SQL query
69 tkz := tokenizer.GetTokenizer()
70 defer tokenizer.PutTokenizer(tkz)
71
72 tokens, err := tkz.Tokenize([]byte(fixture.sql))
73 if err != nil {
74 t.Fatalf("Tokenization failed: %v", err)
75 }
76
77 p := parser.NewParser()
78 astObj := ast.NewAST()
79 defer ast.ReleaseAST(astObj)
80
81 result, err := p.ParseFromModelTokens(tokens)
82 if err != nil {
83 t.Fatalf("Parsing failed for %s: %v", fixture.name, err)
84 }
85
86 astObj.Statements = result.Statements
87
88 // Analyze with our unified analyzer
89 analyzer := NewSQLAnalyzer()
90 report, err := analyzer.Analyze(astObj)
91 if err != nil {
92 t.Fatalf("Analysis failed for %s: %v", fixture.name, err)
93 }
94
95 // Verify expected issues are detected
96 detectedIssueIDs := make(map[string]bool)
97 for _, issue := range report.Issues {
98 detectedIssueIDs[issue.ID] = true
99 }
100
101 // Check all expected issues are found
102 for _, expectedID := range fixture.expectedIssues {
103 if !detectedIssueIDs[expectedID] {
104 t.Errorf("Expected issue %s not detected in %s", expectedID, fixture.name)
105 }
106 }
107
108 // Check for unexpected issues (only if we expect a clean query)
109 if len(fixture.expectedIssues) == 0 && len(report.Issues) > 0 {
110 var issueIDs []string
111 for _, issue := range report.Issues {
112 issueIDs = append(issueIDs, issue.ID)
113 }
114 t.Errorf("Unexpected issues detected in clean query %s: %v", fixture.name, issueIDs)
115 }
116
117 // Verify score expectations
118 if report.OverallScore < fixture.expectedScore {
119 t.Errorf("Score too low for %s: got %d, expected at least %d",
120 fixture.name, report.OverallScore, fixture.expectedScore)
121 }
122

Callers

nothing calls this directly

Calls 12

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
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected