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

Function TestCleanQueries

pkg/advisor/optimizer_test.go:695–736  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Clean query tests (no suggestions expected) ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

693// ---------------------------------------------------------------------------
694
695func TestCleanQueries(t *testing.T) {
696 opt := New()
697
698 cleanQueries := []struct {
699 name string
700 sql string
701 }{
702 {
703 name: "simple SELECT with named columns",
704 sql: "SELECT id, name, email FROM users WHERE active = true",
705 },
706 {
707 name: "JOIN with WHERE and named columns",
708 sql: "SELECT u.id, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE o.status = 'completed'",
709 },
710 {
711 name: "UPDATE with WHERE",
712 sql: "UPDATE users SET active = false WHERE last_login < '2024-01-01'",
713 },
714 {
715 name: "DELETE with WHERE",
716 sql: "DELETE FROM sessions WHERE expired_at < NOW()",
717 },
718 {
719 name: "INSERT statement",
720 sql: "INSERT INTO users (name, email) VALUES ('John', 'john@test.com')",
721 },
722 }
723
724 for _, tt := range cleanQueries {
725 t.Run(tt.name, func(t *testing.T) {
726 result := mustAnalyze(t, opt, tt.sql)
727 // A clean query might still have some info-level suggestions;
728 // the important thing is no error or warning suggestions.
729 for _, s := range result.Suggestions {
730 if s.Severity == SeverityError {
731 t.Errorf("clean query %q produced error suggestion: %s - %s", tt.sql, s.RuleID, s.Message)
732 }
733 }
734 })
735 }
736}
737
738// ---------------------------------------------------------------------------
739// AnalyzeSQL convenience method

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected