Skip to content

Commit

Permalink
Place table rename tests next to each other
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath authored and findepi committed Mar 23, 2022
1 parent 1cc64a9 commit 58c59a9
Showing 1 changed file with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1686,44 +1686,6 @@ public void testRenameSchema()
}
}

@Test
public void testRenameTableAcrossSchema()
{
if (!hasBehavior(SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS)) {
if (!hasBehavior(SUPPORTS_RENAME_TABLE)) {
throw new SkipException("Skipping since rename table is not supported at all");
}
assertQueryFails("ALTER TABLE nation RENAME TO other_schema.yyyy", "This connector does not support renaming tables across schemas");
return;
}

if (!hasBehavior(SUPPORTS_CREATE_SCHEMA)) {
throw new AssertionError("Cannot test ALTER TABLE RENAME across schemas without CREATE SCHEMA, the test needs to be implemented in a connector-specific way");
}

if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new AssertionError("Cannot test ALTER TABLE RENAME across schemas without CREATE TABLE, the test needs to be implemented in a connector-specific way");
}

String tableName = "test_rename_old_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1);

String schemaName = "test_schema_" + randomTableSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);

String renamedTable = schemaName + ".test_rename_new_" + randomTableSuffix();
assertUpdate("ALTER TABLE " + tableName + " RENAME TO " + renamedTable);

assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertQuery("SELECT x FROM " + renamedTable, "VALUES 123");

assertUpdate("DROP TABLE " + renamedTable);
assertUpdate("DROP SCHEMA " + schemaName);

assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertFalse(getQueryRunner().tableExists(getSession(), renamedTable));
}

@Test
public void testAddColumn()
{
Expand Down Expand Up @@ -2053,6 +2015,44 @@ public void testRenameTable()
assertFalse(getQueryRunner().tableExists(getSession(), renamedTable));
}

@Test
public void testRenameTableAcrossSchema()
{
if (!hasBehavior(SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS)) {
if (!hasBehavior(SUPPORTS_RENAME_TABLE)) {
throw new SkipException("Skipping since rename table is not supported at all");
}
assertQueryFails("ALTER TABLE nation RENAME TO other_schema.yyyy", "This connector does not support renaming tables across schemas");
return;
}

if (!hasBehavior(SUPPORTS_CREATE_SCHEMA)) {
throw new AssertionError("Cannot test ALTER TABLE RENAME across schemas without CREATE SCHEMA, the test needs to be implemented in a connector-specific way");
}

if (!hasBehavior(SUPPORTS_CREATE_TABLE)) {
throw new AssertionError("Cannot test ALTER TABLE RENAME across schemas without CREATE TABLE, the test needs to be implemented in a connector-specific way");
}

String tableName = "test_rename_old_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 123 x", 1);

String schemaName = "test_schema_" + randomTableSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);

String renamedTable = schemaName + ".test_rename_new_" + randomTableSuffix();
assertUpdate("ALTER TABLE " + tableName + " RENAME TO " + renamedTable);

assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertQuery("SELECT x FROM " + renamedTable, "VALUES 123");

assertUpdate("DROP TABLE " + renamedTable);
assertUpdate("DROP SCHEMA " + schemaName);

assertFalse(getQueryRunner().tableExists(getSession(), tableName));
assertFalse(getQueryRunner().tableExists(getSession(), renamedTable));
}

@Test
public void testCommentTable()
{
Expand Down

0 comments on commit 58c59a9

Please sign in to comment.