Skip to content

Commit

Permalink
tests(Spanner): enable PG tests to run on emulator (#7572)
Browse files Browse the repository at this point in the history
  • Loading branch information
skuruppu authored Feb 7, 2025
1 parent 5f631ee commit bc9ba08
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Spanner/tests/System/PgBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function setUpTestFixtures(): void
*/
public function testBatchWithDbRole($dbRole, $expected)
{
// Emulator does not support FGAC
// Emulator does not support FGAC for the PG dialect.
$this->skipEmulatorTests();

$error = null;
Expand Down
2 changes: 2 additions & 0 deletions Spanner/tests/System/PgBatchWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class PgBatchWriteTest extends SpannerPgTestCase
*/
public static function setUpTestFixtures(): void
{
// The BatchWrite tests are skipped for the GSQL dialect when running
// against the emulator.
self::skipEmulatorTests();
parent::setUpTestFixtures();

Expand Down
5 changes: 5 additions & 0 deletions Spanner/tests/System/PgPartitionedDmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class PgPartitionedDmlTest extends SpannerPgTestCase

public function testPdml()
{
// Skipping temporarily while we figure out the issue with
// `executePartitionedUpdate` not accepting parameters in
// PG format.
$this->skipEmulatorTests();

$db = self::$database;

$db->updateDdl('CREATE TABLE ' . self::PDML_TABLE . '(
Expand Down
10 changes: 10 additions & 0 deletions Spanner/tests/System/PgQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public function testBindFloat64Parameter()

public function testBindFloat32Parameter()
{
// Emulator as an issue with FLOAT32 for PG.
$this->skipEmulatorTests();
$db = self::$database;

$res = $db->execute('SELECT * FROM ' . self::TABLE_NAME . ' WHERE weight = $1', [
Expand Down Expand Up @@ -547,6 +549,8 @@ public function testBindJsonbParameterNull()

public function testBindPgOidParameter()
{
// Emulator support for PG.OID is pending.
$this->skipEmulatorTests();
$db = self::$database;

$res = $db->execute('SELECT $1', [
Expand All @@ -562,6 +566,8 @@ public function testBindPgOidParameter()

public function testBindPgOidParameterNull()
{
// Emulator support for PG.OID is pending.
$this->skipEmulatorTests();
$db = self::$database;

$res = $db->execute('SELECT $1', [
Expand Down Expand Up @@ -729,6 +735,8 @@ public function arrayTypesEmptyProvider()
*/
public function testBindEmptyArrayOfType($type)
{
// Emulator support for PG.OID is pending.
$this->skipEmulatorTests();
$db = self::$database;

$res = $db->execute('SELECT $1 as foo', [
Expand Down Expand Up @@ -767,6 +775,8 @@ public function arrayTypesNullProvider()
*/
public function testBindNullArrayOfType($type)
{
// Emulator support for PG.OID is pending.
$this->skipEmulatorTests();
$db = self::$database;

$res = $db->execute('SELECT $1 as foo', [
Expand Down
1 change: 1 addition & 0 deletions Spanner/tests/System/PgReadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public function testReadFailsOnDeadlineExceeded()
{
$this->expectException(DeadlineExceededException::class);

// The equiavalent test for the GSQL dialect is also skipped.
$this->skipEmulatorTests();
$db = self::$database;
$keyset = new KeySet(['all' => true]);
Expand Down
2 changes: 2 additions & 0 deletions Spanner/tests/System/PgWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class PgWriteTest extends SpannerPgTestCase
*/
public static function setUpTestFixtures(): void
{
// The equiavalent tests for the GSQL dialect are also skipped.
self::skipEmulatorTests();
parent::setUpTestFixtures();

self::$database->updateDdlBatch([
Expand Down
22 changes: 15 additions & 7 deletions Spanner/tests/System/SpannerPgTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static function setUpTestFixtures(): void
return;
}

self::skipEmulatorTests();
self::getClient();

self::$instance = self::$client->instance(self::INSTANCE_NAME);
Expand Down Expand Up @@ -86,15 +85,24 @@ public static function setUpTestFixtures(): void
name varchar(1024) NOT NULL,
birthday date
)',
'CREATE ROLE ' . self::DATABASE_ROLE,
'CREATE ROLE ' . self::RESTRICTIVE_DATABASE_ROLE,
'GRANT SELECT ON TABLE ' . self::TEST_TABLE_NAME .
' TO ' . self::DATABASE_ROLE,
'GRANT SELECT(id, name), INSERT(id, name), UPDATE(id, name) ON TABLE '
. self::TEST_TABLE_NAME . ' TO ' . self::RESTRICTIVE_DATABASE_ROLE,
]
)->pollUntilComplete();

// Currently, the emulator doesn't support setting roles for the PG
// dialect.
if (!getenv("SPANNER_EMULATOR_HOST")) {
$db->updateDdlBatch(
[
'CREATE ROLE ' . self::DATABASE_ROLE,
'CREATE ROLE ' . self::RESTRICTIVE_DATABASE_ROLE,
'GRANT SELECT ON TABLE ' . self::TEST_TABLE_NAME .
' TO ' . self::DATABASE_ROLE,
'GRANT SELECT(id, name), INSERT(id, name), UPDATE(id, name) ON TABLE '
. self::TEST_TABLE_NAME . ' TO ' . self::RESTRICTIVE_DATABASE_ROLE,
]
)->pollUntilComplete();
}

self::$hasSetUp = true;
}

Expand Down

0 comments on commit bc9ba08

Please sign in to comment.