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

Function TestMissingWhereRule

pkg/advisor/optimizer_test.go:89–141  ·  view source on GitHub ↗

--------------------------------------------------------------------------- OPT-002: Missing WHERE Clause ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

87// ---------------------------------------------------------------------------
88
89func 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

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