From 51b43770aad1dabf6fc2cca6b3e983acb01c3c47 Mon Sep 17 00:00:00 2001 From: Ajumal Date: Wed, 23 Nov 2022 16:53:46 +0530 Subject: [PATCH] skip the FGAC tests in the Spanner Emulator --- Spanner/src/Batch/BatchClient.php | 5 ++ Spanner/src/Database.php | 1 - Spanner/tests/System/BatchTest.php | 29 ++++++++---- Spanner/tests/System/OperationsTest.php | 12 +++++ Spanner/tests/System/SpannerTestCase.php | 60 ++++++++++++------------ Spanner/tests/System/TransactionTest.php | 6 +++ 6 files changed, 73 insertions(+), 40 deletions(-) diff --git a/Spanner/src/Batch/BatchClient.php b/Spanner/src/Batch/BatchClient.php index bab2aba3608e..c3e9df4a6e91 100644 --- a/Spanner/src/Batch/BatchClient.php +++ b/Spanner/src/Batch/BatchClient.php @@ -119,6 +119,11 @@ class BatchClient */ private $databaseName; + /** + * @var string + */ + private $databaseRole; + /** * @var array */ diff --git a/Spanner/src/Database.php b/Spanner/src/Database.php index 5377534c31c2..e2199e6bd242 100644 --- a/Spanner/src/Database.php +++ b/Spanner/src/Database.php @@ -2104,5 +2104,4 @@ private function getCreateDbStatement($dialect) return sprintf('CREATE DATABASE `%s`', $databaseId); } - } diff --git a/Spanner/tests/System/BatchTest.php b/Spanner/tests/System/BatchTest.php index b6577ca19757..fc529b011124 100644 --- a/Spanner/tests/System/BatchTest.php +++ b/Spanner/tests/System/BatchTest.php @@ -22,6 +22,7 @@ use Google\Cloud\Spanner\KeyRange; use Google\Cloud\Spanner\KeySet; use Google\Cloud\Core\Exception\ServiceException; +use Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect; /** * @group spanner @@ -49,16 +50,18 @@ public static function set_up_before_class() self::$tableName ))->pollUntilComplete(); - $db->updateDdl(sprintf( - 'CREATE ROLE %s', - self::$databaseRole - ))->pollUntilComplete(); - - $db->updateDdl(sprintf( - 'GRANT SELECT(id) ON TABLE %s TO ROLE %s', - self::$tableName, - self::$databaseRole - ))->pollUntilComplete(); + if ($db->info()['databaseDialect'] == DatabaseDialect::GOOGLE_STANDARD_SQL) { + $db->updateDdl(sprintf( + 'CREATE ROLE %s', + self::$databaseRole + ))->pollUntilComplete(); + + $db->updateDdl(sprintf( + 'GRANT SELECT(id) ON TABLE %s TO ROLE %s', + self::$tableName, + self::$databaseRole + ))->pollUntilComplete(); + } self::seedTable(); } @@ -122,6 +125,9 @@ public function testBatch() public function testBatchWithRestrictiveDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $query = 'SELECT id, decade @@ -155,6 +161,9 @@ public function testBatchWithRestrictiveDatabaseRole() public function testBatchWithDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + self::$database->updateDdl(sprintf( 'GRANT SELECT ON TABLE %s TO ROLE %s', self::$tableName, diff --git a/Spanner/tests/System/OperationsTest.php b/Spanner/tests/System/OperationsTest.php index 9473c2e3e119..cb5bbbf1c6b4 100644 --- a/Spanner/tests/System/OperationsTest.php +++ b/Spanner/tests/System/OperationsTest.php @@ -200,6 +200,9 @@ public function testReadNonExistentSingleKeyFromIndex() public function testInsertWithDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithReaderDatabaseRole; try { @@ -216,6 +219,9 @@ public function testInsertWithDatabaseRole() public function testInsertWithRestrictiveDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithReaderDatabaseRole; try { @@ -232,6 +238,9 @@ public function testInsertWithRestrictiveDatabaseRole() public function testReadWithDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithReaderDatabaseRole; $keySet = self::$client->keySet([ @@ -246,6 +255,9 @@ public function testReadWithDatabaseRole() public function testReadWithRestrictiveDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithRestrictiveDatabaseRole; $keySet = self::$client->keySet([ diff --git a/Spanner/tests/System/SpannerTestCase.php b/Spanner/tests/System/SpannerTestCase.php index f23d34ad06c6..5bdda2b7b83c 100644 --- a/Spanner/tests/System/SpannerTestCase.php +++ b/Spanner/tests/System/SpannerTestCase.php @@ -82,38 +82,40 @@ public static function set_up_before_class() ON ' . self::TEST_TABLE_NAME . ' (name)' )->pollUntilComplete(); - $db->updateDdl( - 'CREATE ROLE ' . self::DATABASE_ROLE - )->pollUntilComplete(); - $db->updateDdl( - 'CREATE ROLE ' . self::RESTRICTIVE_DATABASE_ROLE - )->pollUntilComplete(); - - $db->updateDdl( - 'GRANT SELECT ON TABLE ' . self::TEST_TABLE_NAME . ' TO ROLE ' . self::DATABASE_ROLE - )->pollUntilComplete(); - $db->updateDdl( - 'GRANT SELECT(id, name), INSERT(id, name), UPDATE(id, name) ON TABLE ' - . self::TEST_TABLE_NAME . ' TO ROLE ' . self::RESTRICTIVE_DATABASE_ROLE - )->pollUntilComplete(); - self::$database = $db; self::$database2 = self::getDatabaseInstance(self::$dbName); - self::$databaseWithReaderDatabaseRole = self::getDatabaseFromInstance( - self::$dbName, - ['databaseRole' => self::DATABASE_ROLE] - ); - - self::$databaseWithRestrictiveDatabaseRole = self::getDatabaseInstance( - self::$dbName, - ['databaseRole' => self::RESTRICTIVE_DATABASE_ROLE] - ); - - self::$databaseWithSessionPoolRestrictiveDatabaseRole = self::getDatabaseWithSessionPool( - self::$dbName, - ['minSessions' => 1, 'maxSession' => 2, 'databaseRole' => self::RESTRICTIVE_DATABASE_ROLE] - ); + if ($db->info()['databaseDialect'] == DatabaseDialect::GOOGLE_STANDARD_SQL) { + $db->updateDdl( + 'CREATE ROLE ' . self::DATABASE_ROLE + )->pollUntilComplete(); + $db->updateDdl( + 'CREATE ROLE ' . self::RESTRICTIVE_DATABASE_ROLE + )->pollUntilComplete(); + + $db->updateDdl( + 'GRANT SELECT ON TABLE ' . self::TEST_TABLE_NAME . ' TO ROLE ' . self::DATABASE_ROLE + )->pollUntilComplete(); + $db->updateDdl( + 'GRANT SELECT(id, name), INSERT(id, name), UPDATE(id, name) ON TABLE ' + . self::TEST_TABLE_NAME . ' TO ROLE ' . self::RESTRICTIVE_DATABASE_ROLE + )->pollUntilComplete(); + + self::$databaseWithReaderDatabaseRole = self::getDatabaseFromInstance( + self::$dbName, + ['databaseRole' => self::DATABASE_ROLE] + ); + + self::$databaseWithRestrictiveDatabaseRole = self::getDatabaseInstance( + self::$dbName, + ['databaseRole' => self::RESTRICTIVE_DATABASE_ROLE] + ); + + self::$databaseWithSessionPoolRestrictiveDatabaseRole = self::getDatabaseWithSessionPool( + self::$dbName, + ['minSessions' => 1, 'maxSession' => 2, 'databaseRole' => self::RESTRICTIVE_DATABASE_ROLE] + ); + } self::$hasSetUp = true; } diff --git a/Spanner/tests/System/TransactionTest.php b/Spanner/tests/System/TransactionTest.php index 43051b8dccea..7fa4f0c62b94 100644 --- a/Spanner/tests/System/TransactionTest.php +++ b/Spanner/tests/System/TransactionTest.php @@ -223,6 +223,9 @@ public function testStrongRead() public function testRunTransactionWithDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithRestrictiveDatabaseRole; $row = $this->getRow(); @@ -255,6 +258,9 @@ public function testRunTransactionWithDatabaseRole() public function testRunTransactionWithSessionPoolDatabaseRole() { + // Emulator does not support FGAC + $this->skipEmulatorTests(); + $db = self::$databaseWithSessionPoolRestrictiveDatabaseRole; $row = $this->getRow();