-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfingerprint_test.go
More file actions
53 lines (47 loc) · 1.38 KB
/
fingerprint_test.go
File metadata and controls
53 lines (47 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package qshape
import (
"strings"
"testing"
)
func TestFingerprintStable(t *testing.T) {
fp1, err := Fingerprint("SELECT id FROM users WHERE id = 1")
if err != nil {
t.Fatal(err)
}
fp2, err := Fingerprint("SELECT id FROM users WHERE id = 1")
if err != nil {
t.Fatal(err)
}
if fp1 != fp2 {
t.Errorf("fingerprint not stable: %s vs %s", fp1, fp2)
}
if !strings.HasPrefix(fp1, "sha1:") {
t.Errorf("expected sha1: prefix, got %q", fp1)
}
}
func TestFingerprintIgnoresWhitespace(t *testing.T) {
a, _ := Fingerprint("SELECT id FROM users WHERE id = 1")
b, _ := Fingerprint("SELECT id FROM users WHERE id=1")
if a != b {
t.Errorf("whitespace variation changed fingerprint: %s vs %s", a, b)
}
}
func TestFingerprintIgnoresLiterals(t *testing.T) {
a, _ := Fingerprint("SELECT id FROM users WHERE id = 1")
b, _ := Fingerprint("SELECT id FROM users WHERE id = 42")
if a != b {
t.Errorf("literal variation changed fingerprint: %s vs %s", a, b)
}
}
func TestFingerprintDistinguishesColumns(t *testing.T) {
a, _ := Fingerprint("SELECT id FROM users WHERE id = 1")
b, _ := Fingerprint("SELECT id FROM users WHERE name = 'x'")
if a == b {
t.Errorf("different predicates should fingerprint differently, both %s", a)
}
}
func TestFingerprintInvalid(t *testing.T) {
if _, err := Fingerprint("SELECT FROM WHERE"); err == nil {
t.Error("expected error on invalid SQL")
}
}