(t *testing.T)
| 51 | if got != tt.want { |
| 52 | t.Errorf("classifyQuery(%q) = %q, want %q", tt.cmdType, got, tt.want) |
| 53 | } |
| 54 | }) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestNormalizeQueryHash(t *testing.T) { |
| 59 | // Same query with different literal values should produce the same hash |
| 60 | h1 := normalizeQueryHash("SELECT * FROM users WHERE id = 1") |
| 61 | h2 := normalizeQueryHash("SELECT * FROM users WHERE id = 2") |
| 62 | if h1 != h2 { |
| 63 | t.Errorf("Expected same hash for queries differing only in literals, got %d and %d", h1, h2) |
| 64 | } |
| 65 | |
| 66 | // Same query with different string literals |
| 67 | h3 := normalizeQueryHash("SELECT * FROM users WHERE name = 'alice'") |
| 68 | h4 := normalizeQueryHash("SELECT * FROM users WHERE name = 'bob'") |
| 69 | if h3 != h4 { |
| 70 | t.Errorf("Expected same hash for queries differing only in string literals, got %d and %d", h3, h4) |
| 71 | } |
| 72 | |
| 73 | // Different queries should produce different hashes |
| 74 | h5 := normalizeQueryHash("SELECT * FROM users WHERE id = 1") |
| 75 | h6 := normalizeQueryHash("SELECT * FROM orders WHERE id = 1") |
| 76 | if h5 == h6 { |
| 77 | t.Errorf("Expected different hashes for different queries, both got %d", h5) |
| 78 | } |
| 79 | |
| 80 | // Whitespace normalization |
| 81 | h7 := normalizeQueryHash("SELECT * FROM users WHERE id = 1") |
| 82 | h8 := normalizeQueryHash("SELECT * FROM users WHERE id = 1") |
| 83 | if h7 != h8 { |
| 84 | t.Errorf("Expected same hash after whitespace normalization, got %d and %d", h7, h8) |
| 85 | } |
| 86 | |
| 87 | // Case normalization |
| 88 | h9 := normalizeQueryHash("select * from users where id = 1") |
| 89 | h10 := normalizeQueryHash("SELECT * FROM users WHERE id = 1") |
| 90 | if h9 != h10 { |
| 91 | t.Errorf("Expected same hash after case normalization, got %d and %d", h9, h10) |
| 92 | } |
| 93 | |
| 94 | // Keywords in IS predicates should not be normalized away as literals. |
| 95 | h11 := normalizeQueryHash("SELECT * FROM users WHERE active IS TRUE") |
| 96 | h12 := normalizeQueryHash("SELECT * FROM users WHERE active IS NULL") |
| 97 | if h11 == h12 { |
| 98 | t.Errorf("Expected different hashes for IS TRUE vs IS NULL predicates, both got %d", h11) |
nothing calls this directly
no test coverage detected