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

Function TestCartesianProductRule

pkg/advisor/optimizer_test.go:147–176  ·  view source on GitHub ↗

--------------------------------------------------------------------------- OPT-003: Cartesian Product Detection ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

145// ---------------------------------------------------------------------------
146
147func TestCartesianProductRule(t *testing.T) {
148 opt := New()
149
150 tests := []struct {
151 name string
152 sql string
153 wantHit bool
154 }{
155 {
156 name: "Single table does not trigger",
157 sql: "SELECT id FROM users",
158 wantHit: false,
159 },
160 {
161 name: "Explicit JOIN does not trigger",
162 sql: "SELECT u.id, o.total FROM users u JOIN orders o ON u.id = o.user_id",
163 wantHit: false,
164 },
165 }
166
167 for _, tt := range tests {
168 t.Run(tt.name, func(t *testing.T) {
169 result := mustAnalyze(t, opt, tt.sql)
170 got := hasSuggestion(result, "OPT-003")
171 if got != tt.wantHit {
172 t.Errorf("hasSuggestion(OPT-003) = %v, want %v for SQL %q", got, tt.wantHit, tt.sql)
173 }
174 })
175 }
176}
177
178func TestCartesianProductRuleDirect(t *testing.T) {
179 // Test with directly constructed AST to ensure rule logic works

Callers

nothing calls this directly

Calls 5

mustAnalyzeFunction · 0.85
hasSuggestionFunction · 0.85
RunMethod · 0.80
NewFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected