forked from c4pt0r/kvql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_fuzz_test.go
61 lines (48 loc) · 1.39 KB
/
parser_fuzz_test.go
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
54
55
56
57
58
59
60
61
package kvql
import "testing"
type fuzzQueryTxn struct{}
func (t *fuzzQueryTxn) Get(key []byte) ([]byte, error) {
return nil, nil
}
func (t *fuzzQueryTxn) Put(key []byte, value []byte) error {
return nil
}
func (t *fuzzQueryTxn) BatchPut(kvs []KVPair) error {
return nil
}
func (t *fuzzQueryTxn) Delete(key []byte) error {
return nil
}
func (t *fuzzQueryTxn) BatchDelete(key [][]byte) error {
return nil
}
func (t *fuzzQueryTxn) Cursor() (Cursor, error) {
return &fuzzQueryCursor{}, nil
}
type fuzzQueryCursor struct{}
func (c *fuzzQueryCursor) Seek(key []byte) error {
return nil
}
func (c *fuzzQueryCursor) Next() ([]byte, []byte, error) {
return nil, nil, nil
}
func FuzzSQLParser(f *testing.F) {
tests := []string{
"select key, int(value) where int(key) + 1 >= 1 & (int(value) - 1 > 10 | int(value) <= 20)",
"select key, int(value) where key ^= 'key' order by key limit 20, 10",
"select * where key in ('k1', 'k2', 'k3')",
"select * where (key between 'k1' and 'k3') & int(value) between 1 and 10",
"select key, json(value)['test'] where key ^= 'k' & json(value)['test'][1] = 'v1'",
"put ('k1', 'v1'), ('k1', 'V_' + upper(key)), ('k3', lower('V3'))",
"remove 'k1', 'k2'",
"delete where key ^='prefix' and value = 'v2'",
}
for _, t := range tests {
f.Add(t)
}
txn := &fuzzQueryTxn{}
f.Fuzz(func(t *testing.T, query string) {
o := NewOptimizer(query)
o.buildPlan(txn)
})
}