-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Vitess query validation support for update changes primary vindex…
… column (#49) * Add Vitess query validation support for `update changes primary vindex column` * linters
- Loading branch information
Showing
3 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?hh // strict | ||
|
||
namespace Slack\SQLFake; | ||
|
||
use function Facebook\FBExpect\expect; | ||
use type Facebook\HackTest\HackTest; | ||
|
||
final class UpdateQueryValidatorTest extends HackTest { | ||
private static ?AsyncMysqlConnection $conn; | ||
|
||
<<__Override>> | ||
public static async function beforeFirstTestAsync(): Awaitable<void> { | ||
static::$conn = await SharedSetup::initVitessAsync(); | ||
// block hole logging | ||
// ? copied from SelectQueryValidatorTest.php, not sure what that means. | ||
Logger::setHandle(new \Facebook\CLILib\TestLib\StringOutput()); | ||
} | ||
|
||
<<__Override>> | ||
public async function beforeEachTestAsync(): Awaitable<void> { | ||
restore('vitess_setup'); | ||
QueryContext::$strictSchemaMode = false; | ||
QueryContext::$strictSQLMode = false; | ||
} | ||
|
||
public async function testUpdateChangesPrimaryVindex(): Awaitable<void> { | ||
$conn = static::$conn as nonnull; | ||
|
||
$unsupported_test_cases = vec[ | ||
'update vt_table1 set id=1 where id=1', | ||
'update vt_table2 set vt_table1_id=1 where id=1' | ||
]; | ||
|
||
foreach($unsupported_test_cases as $sql) { | ||
expect(() ==> $conn->query($sql))->toThrow( | ||
SQLFakeVitessQueryViolation::class, | ||
'Vitess query validation error: unsupported: update changes primary vindex column', | ||
); | ||
} | ||
|
||
$supported_test_cases = vec[ | ||
"update vt_table1 set name='foo' where id = 1" | ||
]; | ||
|
||
foreach ($supported_test_cases as $sql) { | ||
expect(() ==> $conn->query($sql))->notToThrow(SQLFakeVitessQueryViolation::class); | ||
} | ||
|
||
} | ||
} |