Skip to content

Commit

Permalink
Add method to test DDB clients for resetting tables in between tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmollaverdi authored Aug 7, 2024
1 parent e7197de commit 64f40ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class DefaultTestDynamoDbClient(
override val dynamoDbStreams = buildDynamoDbStreams(hostName, port)

override fun startUp() {
reset()
}

override fun shutDown() {
dynamoDb.shutdown()
dynamoDbStreams.shutdown()
}

override fun reset() {
// Cleans up the tables before each run.
for (tableName in dynamoDb.listTables().tableNames) {
dynamoDb.deleteTable(tableName)
Expand All @@ -39,9 +48,4 @@ class DefaultTestDynamoDbClient(
dynamoDb.createTable(table)
}
}

override fun shutDown() {
dynamoDb.shutdown()
dynamoDbStreams.shutdown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ interface TestDynamoDbClient : Service {
fun <DB : LogicalDb> logicalDb(type: Class<DB>, mapperConfig: DynamoDBMapperConfig): DB {
return logicalDb(type.kotlin, mapperConfig)
}

/** Cleans up tables in between test runs. */
fun reset()
}

inline fun <reified DB : LogicalDb> TestDynamoDbClient.logicalDb(): DB {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class DefaultTestDynamoDbClient(
override val asyncDynamoDbStreams = buildAsyncDynamoDbStreams(hostName, port)

override fun startUp() {
reset()
}

override fun shutDown() {
dynamoDb.close()
dynamoDbStreams.close()
}

override fun reset() {
// Cleans up the tables before each run.
for (tableName in dynamoDb.listTables().tableNames()) {
dynamoDb.deleteTable(DeleteTableRequest.builder().tableName(tableName).build())
Expand All @@ -42,9 +51,4 @@ class DefaultTestDynamoDbClient(
dynamoDb.createTable(table)
}
}

override fun shutDown() {
dynamoDb.close()
dynamoDbStreams.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ interface TestDynamoDbClient : Service {
): DB {
return asyncLogicalDb(type.kotlin, extensions)
}

/** Cleans up tables in between test runs. */
fun reset()
}

inline fun <reified DB : LogicalDb> TestDynamoDbClient.logicalDb(
Expand Down

0 comments on commit 64f40ef

Please sign in to comment.