Skip to content

Commit

Permalink
skip the FGAC tests in the Spanner Emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ajupazhamayil committed Nov 23, 2022
1 parent fe0fd85 commit 613dc32
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 40 deletions.
5 changes: 5 additions & 0 deletions Spanner/src/Batch/BatchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class BatchClient
*/
private $databaseName;

/**
* @var string
*/
private $databaseRole;

/**
* @var array
*/
Expand Down
1 change: 0 additions & 1 deletion Spanner/src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2104,5 +2104,4 @@ private function getCreateDbStatement($dialect)

return sprintf('CREATE DATABASE `%s`', $databaseId);
}

}
29 changes: 19 additions & 10 deletions Spanner/tests/System/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -122,6 +125,9 @@ public function testBatch()

public function testBatchWithRestrictiveDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$query = 'SELECT
id,
decade
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions Spanner/tests/System/OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public function testReadNonExistentSingleKeyFromIndex()

public function testInsertWithDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithReaderDatabaseRole;

try {
Expand All @@ -216,6 +219,9 @@ public function testInsertWithDatabaseRole()

public function testInsertWithRestrictiveDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithReaderDatabaseRole;

try {
Expand All @@ -232,6 +238,9 @@ public function testInsertWithRestrictiveDatabaseRole()

public function testReadWithDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithReaderDatabaseRole;

$keySet = self::$client->keySet([
Expand All @@ -246,6 +255,9 @@ public function testReadWithDatabaseRole()

public function testReadWithRestrictiveDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithRestrictiveDatabaseRole;

$keySet = self::$client->keySet([
Expand Down
60 changes: 31 additions & 29 deletions Spanner/tests/System/SpannerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions Spanner/tests/System/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ public function testStrongRead()

public function testRunTransactionWithDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithRestrictiveDatabaseRole;

$row = $this->getRow();
Expand Down Expand Up @@ -255,6 +258,9 @@ public function testRunTransactionWithDatabaseRole()

public function testRunTransactionWithSessionPoolDatabaseRole()
{
// Emulator does not support FGAC
$this->skipEmulatorTests();

$db = self::$databaseWithSessionPoolRestrictiveDatabaseRole;

$row = $this->getRow();
Expand Down

0 comments on commit 613dc32

Please sign in to comment.