Skip to content

Commit

Permalink
Extract test helper function to truncate all tables (#10286)
Browse files Browse the repository at this point in the history
Multiple persistence test truncates tables when they need to reset the
state of the DB. All subclasses of `BaseDatabaseConfigPersistenceTest`
now relies on `truncateAllTables` to do so.
  • Loading branch information
malikdiarra authored Feb 14, 2022
1 parent 9177fd2 commit 579ace4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.db.Database;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -53,6 +54,12 @@ public static void dbDown() {
container.close();
}

protected static void truncateAllTables() throws SQLException {
database.query(ctx -> ctx
.execute(
"TRUNCATE TABLE state, actor_catalog, actor_catalog_fetch_event, connection_operation, connection, operation, actor_oauth_parameter, actor, actor_definition, workspace"));
}

protected static final StandardSourceDefinition SOURCE_GITHUB = new StandardSourceDefinition()
.withName("GitHub")
.withSourceDefinitionId(UUID.fromString("ef69ef6e-aa7f-4af1-a01d-ef775033524e"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public void setup() throws Exception {
new ConfigsDatabaseMigrator(database, DatabaseConfigPersistenceLoadDataTest.class.getName());
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
MigrationDevHelper.runLastMigration(devDatabaseMigrator);
database.query(ctx -> ctx
.execute(
"TRUNCATE TABLE state, actor_catalog, actor_catalog_fetch_event, connection_operation, connection, operation, actor_oauth_parameter, actor, actor_definition, workspace"));
truncateAllTables();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public static void setup() throws Exception {
new ConfigsDatabaseMigrator(database, DatabaseConfigPersistenceLoadDataTest.class.getName());
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
MigrationDevHelper.runLastMigration(devDatabaseMigrator);
database.query(ctx -> ctx
.execute(
"TRUNCATE TABLE state, actor_catalog, actor_catalog_fetch_event, connection_operation, connection, operation, actor_oauth_parameter, actor, actor_definition, workspace"));
truncateAllTables();
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public void setup() throws Exception {
new ConfigsDatabaseMigrator(database, DatabaseConfigPersistenceLoadDataTest.class.getName());
final DevDatabaseMigrator devDatabaseMigrator = new DevDatabaseMigrator(configsDatabaseMigrator);
MigrationDevHelper.runLastMigration(devDatabaseMigrator);
database.query(ctx -> ctx
.execute(
"TRUNCATE TABLE state, actor_catalog, actor_catalog_fetch_event, connection_operation, connection, operation, actor_oauth_parameter, actor, actor_definition, workspace"));
truncateAllTables();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public static void tearDown() throws Exception {

@BeforeEach
public void resetDatabase() throws SQLException {
database.query(ctx -> ctx
.execute(
"TRUNCATE TABLE state, actor_catalog, actor_catalog_fetch_event, connection_operation, connection, operation, actor_oauth_parameter, actor, actor_definition, workspace"));
truncateAllTables();
}

@Test
Expand Down

0 comments on commit 579ace4

Please sign in to comment.