--------------------------------------------------------------------------- OPT-003: Cartesian Product Detection ---------------------------------------------------------------------------
(t *testing.T)
| 145 | // --------------------------------------------------------------------------- |
| 146 | |
| 147 | func 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 | |
| 178 | func TestCartesianProductRuleDirect(t *testing.T) { |
| 179 | // Test with directly constructed AST to ensure rule logic works |
nothing calls this directly
no test coverage detected