--------------------------------------------------------------------------- OPT-004: SELECT DISTINCT Overuse ---------------------------------------------------------------------------
(t *testing.T)
| 257 | // --------------------------------------------------------------------------- |
| 258 | |
| 259 | func TestDistinctOveruseRule(t *testing.T) { |
| 260 | opt := New() |
| 261 | |
| 262 | tests := []struct { |
| 263 | name string |
| 264 | sql string |
| 265 | wantHit bool |
| 266 | }{ |
| 267 | { |
| 268 | name: "DISTINCT without JOIN triggers info", |
| 269 | sql: "SELECT DISTINCT status FROM orders", |
| 270 | wantHit: true, |
| 271 | }, |
| 272 | { |
| 273 | name: "No DISTINCT does not trigger", |
| 274 | sql: "SELECT status FROM orders", |
| 275 | wantHit: false, |
| 276 | }, |
| 277 | } |
| 278 | |
| 279 | for _, tt := range tests { |
| 280 | t.Run(tt.name, func(t *testing.T) { |
| 281 | result := mustAnalyze(t, opt, tt.sql) |
| 282 | got := hasSuggestion(result, "OPT-004") |
| 283 | if got != tt.wantHit { |
| 284 | t.Errorf("hasSuggestion(OPT-004) = %v, want %v for SQL %q", got, tt.wantHit, tt.sql) |
| 285 | } |
| 286 | }) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | func TestDistinctOveruseRuleDirect(t *testing.T) { |
| 291 | rule := &DistinctOveruseRule{} |
nothing calls this directly
no test coverage detected