-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSelectQueryValidatorTest.php
More file actions
77 lines (65 loc) · 2.51 KB
/
SelectQueryValidatorTest.php
File metadata and controls
77 lines (65 loc) · 2.51 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?hh // strict
namespace Slack\SQLFake;
use function Facebook\FBExpect\expect;
use type Facebook\HackTest\HackTest;
// most of the test cases are inspired by
// https://github.com/vitessio/vitess/blob/master/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
final class SelectQueryValidatorTest extends HackTest {
private static ?AsyncMysqlConnection $conn;
<<__Override>>
public static async function beforeFirstTestAsync(): Awaitable<void> {
static::$conn = await SharedSetup::initVitessAsync();
// block hole logging
Logger::setHandle(new \HH\Lib\IO\MemoryHandle());
}
<<__Override>>
public async function beforeEachTestAsync(): Awaitable<void> {
restore('vitess_setup');
QueryContext::$strictSchemaMode = false;
QueryContext::$strictSQLMode = false;
}
public async function testScatterByColumns(): Awaitable<void> {
$conn = static::$conn as nonnull;
$unsupported_test_cases = vec[
"select * from vt_table1 where id=2 and name='hi' group by id",
'select * from vt_table1 group by name',
];
foreach ($unsupported_test_cases as $sql) {
expect(() ==> $conn->query($sql))->toThrow(
SQLFakeVitessQueryViolation::class,
'Vitess query validation error: unsupported: in scatter query: group by column must reference column in SELECT list',
);
}
$unsupported_test_cases = vec[
'select * from vt_table1 where id in (1, 2) order by id',
'select id from vt_table1 order by name',
'select id, count(*) from vt_table1 group by id order by c1',
];
$supported_test_cases = vec[
'select * from vt_table1 where id=2 order by name',
"select * from vt_table1 where id=2 and name='bob' order by name,id",
];
foreach ($unsupported_test_cases as $sql) {
expect(() ==> $conn->query($sql))->toThrow(
SQLFakeVitessQueryViolation::class,
'Vitess query validation error: unsupported: in scatter query: order by column must reference column in SELECT list',
);
}
foreach ($supported_test_cases as $sql) {
expect(() ==> $conn->query($sql))->notToThrow(SQLFakeVitessQueryViolation::class);
}
}
public async function testUnionsNotAllowed(): Awaitable<void> {
$conn = static::$conn as nonnull;
$test_cases = vec[
'select * from vt_table1 union select * from vt_table2',
'select id from vt_table1 union all select id from vt_table2',
];
foreach ($test_cases as $sql) {
expect(() ==> $conn->query($sql))->toThrow(
SQLFakeVitessQueryViolation::class,
'Vitess query validation error: unsupported: UNION cannot be executed as a single route',
);
}
}
}