--------------------------------------------------------------------------- OPT-002: Missing WHERE Clause ---------------------------------------------------------------------------
(t *testing.T)
| 87 | // --------------------------------------------------------------------------- |
| 88 | |
| 89 | func TestMissingWhereRule(t *testing.T) { |
| 90 | opt := New() |
| 91 | |
| 92 | tests := []struct { |
| 93 | name string |
| 94 | sql string |
| 95 | wantHit bool |
| 96 | }{ |
| 97 | { |
| 98 | name: "UPDATE without WHERE triggers", |
| 99 | sql: "UPDATE users SET active = true", |
| 100 | wantHit: true, |
| 101 | }, |
| 102 | { |
| 103 | name: "UPDATE with WHERE does not trigger", |
| 104 | sql: "UPDATE users SET active = true WHERE id = 1", |
| 105 | wantHit: false, |
| 106 | }, |
| 107 | { |
| 108 | name: "DELETE without WHERE triggers", |
| 109 | sql: "DELETE FROM orders", |
| 110 | wantHit: true, |
| 111 | }, |
| 112 | { |
| 113 | name: "DELETE with WHERE does not trigger", |
| 114 | sql: "DELETE FROM orders WHERE status = 'expired'", |
| 115 | wantHit: false, |
| 116 | }, |
| 117 | { |
| 118 | name: "SELECT without WHERE does not trigger (rule only applies to UPDATE/DELETE)", |
| 119 | sql: "SELECT * FROM users", |
| 120 | wantHit: false, |
| 121 | }, |
| 122 | } |
| 123 | |
| 124 | for _, tt := range tests { |
| 125 | t.Run(tt.name, func(t *testing.T) { |
| 126 | result := mustAnalyze(t, opt, tt.sql) |
| 127 | got := hasSuggestion(result, "OPT-002") |
| 128 | if got != tt.wantHit { |
| 129 | t.Errorf("hasSuggestion(OPT-002) = %v, want %v for SQL %q", got, tt.wantHit, tt.sql) |
| 130 | } |
| 131 | // Verify severity is error for dangerous operations |
| 132 | if tt.wantHit { |
| 133 | for _, s := range result.Suggestions { |
| 134 | if s.RuleID == "OPT-002" && s.Severity != SeverityError { |
| 135 | t.Errorf("expected severity %q for OPT-002, got %q", SeverityError, s.Severity) |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | }) |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // --------------------------------------------------------------------------- |
| 144 | // OPT-003: Cartesian Product Detection |
nothing calls this directly
no test coverage detected