forked from cashapp/misk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace most test modules with testFixtures (cashapp#2793)
Replace most test modules with testFixtures
- Loading branch information
tso
authored
May 24, 2023
1 parent
9b60615
commit 64c4bed
Showing
168 changed files
with
5,682 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
misk-aws-dynamodb-testing/src/main/kotlin/misk/aws/dynamodb/testing/DockerDynamoDb.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
plugins { | ||
kotlin("jvm") | ||
`java-library` | ||
`java-test-fixtures` | ||
} | ||
|
||
dependencies { | ||
api("com.amazonaws:aws-java-sdk-core:1.11.960") | ||
api(Dependencies.kotlinLogging) | ||
api(Dependencies.javaxInject) | ||
api(Dependencies.awsDynamodb) | ||
api(Dependencies.awsJavaSdkCore) | ||
api(Dependencies.guice) | ||
api(Dependencies.javaxInject) | ||
api(Dependencies.kotlinLogging) | ||
api(project(":misk-aws")) | ||
api(project(":misk-core")) | ||
api(project(":misk-inject")) | ||
implementation(Dependencies.kotlinReflect) | ||
implementation(Dependencies.wispLogging) | ||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.0") | ||
implementation(project(":misk-exceptions-dynamodb")) | ||
implementation(project(":misk-service")) | ||
|
||
testFixturesApi(Dependencies.awsDynamodb) | ||
testFixturesApi(Dependencies.guice) | ||
testFixturesApi(Dependencies.javaxInject) | ||
testFixturesApi(Dependencies.tempestTestingInternal) | ||
testFixturesApi(project(":misk-aws-dynamodb")) | ||
testFixturesApi(project(":misk-inject")) | ||
testFixturesApi(project(":misk-testing")) | ||
testFixturesImplementation(Dependencies.kotlinReflect) | ||
testFixturesImplementation(Dependencies.tempestTesting) | ||
testFixturesImplementation(Dependencies.tempestTestingDocker) | ||
testFixturesImplementation(Dependencies.tempestTestingJvm) | ||
testFixturesImplementation(project(":misk-core")) | ||
testFixturesImplementation(project(":misk-service")) | ||
|
||
testImplementation(Dependencies.assertj) | ||
testImplementation(Dependencies.junitApi) | ||
testImplementation(project(":misk-aws-dynamodb")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
misk-aws-dynamodb/src/testFixtures/kotlin/misk/aws/dynamodb/testing/DockerDynamoDbModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package misk.aws.dynamodb.testing | ||
|
||
import app.cash.tempest.testing.DockerDynamoDbServer | ||
import app.cash.tempest.testing.TestTable | ||
import app.cash.tempest.testing.internal.TestDynamoDbService | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams | ||
import com.google.common.util.concurrent.AbstractService | ||
import com.google.inject.Provides | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlin.reflect.KClass | ||
import misk.ServiceModule | ||
import misk.dynamodb.DynamoDbHealthCheck | ||
import misk.dynamodb.DynamoDbService | ||
import misk.dynamodb.RequiredDynamoDbTable | ||
import misk.healthchecks.HealthCheck | ||
import misk.inject.KAbstractModule | ||
|
||
/** | ||
* Spins up a docker container for testing. It clears the table content before each test starts. | ||
* | ||
* Note that this may not be used alongside [InProcessDynamoDbModule]. DynamoDB may execute in Docker or | ||
* in-process, but never both. | ||
*/ | ||
class DockerDynamoDbModule( | ||
private val tables: List<DynamoDbTable> | ||
) : KAbstractModule() { | ||
|
||
constructor(vararg tables: DynamoDbTable) : this(tables.toList()) | ||
constructor(vararg tables: KClass<*>) : this(tables.map { DynamoDbTable(it) }) | ||
|
||
override fun configure() { | ||
for (table in tables) { | ||
multibind<DynamoDbTable>().toInstance(table) | ||
} | ||
multibind<HealthCheck>().to<DynamoDbHealthCheck>() | ||
bind<DynamoDbService>().to<DockerDynamoDbService>() | ||
install(ServiceModule<DynamoDbService>().dependsOn<TestDynamoDb>()) | ||
install(ServiceModule<TestDynamoDb>()) | ||
} | ||
|
||
@Provides @Singleton | ||
fun provideRequiredTables(): List<RequiredDynamoDbTable> = | ||
tables.map { RequiredDynamoDbTable(it.tableName) } | ||
|
||
@Provides @Singleton | ||
fun providesTestDynamoDb(): TestDynamoDb { | ||
return TestDynamoDb( | ||
TestDynamoDbService.create( | ||
serverFactory = DockerDynamoDbServer.Factory, | ||
tables = tables.map { TestTable.create(it.tableClass, it.configureTable) }, | ||
port = null | ||
) | ||
) | ||
} | ||
|
||
@Provides @Singleton | ||
fun providesAmazonDynamoDB(testDynamoDb: TestDynamoDb): AmazonDynamoDB { | ||
return testDynamoDb.service.client.dynamoDb | ||
} | ||
|
||
@Provides @Singleton | ||
fun providesAmazonDynamoDBStreams(testDynamoDb: TestDynamoDb): AmazonDynamoDBStreams { | ||
return testDynamoDb.service.client.dynamoDbStreams | ||
} | ||
|
||
/** This service does nothing; depending on Tempest's [TestDynamoDb] is sufficient. */ | ||
@Singleton | ||
private class DockerDynamoDbService @Inject constructor() : AbstractService(), DynamoDbService { | ||
override fun doStart() = notifyStarted() | ||
override fun doStop() = notifyStopped() | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
misk-aws-dynamodb/src/testFixtures/kotlin/misk/aws/dynamodb/testing/DynamoDbTable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package misk.aws.dynamodb.testing | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable | ||
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.full.findAnnotation | ||
|
||
/** | ||
* Use this with [DockerDynamoDbModule] or [InProcessDynamoDbModule] to configure your DynamoDB | ||
* tables for each test execution. | ||
* | ||
* Use [configureTable] to customize the table creation request for testing, such as to configure | ||
* the secondary indexes required by `ProjectionType.ALL`. | ||
*/ | ||
data class DynamoDbTable( | ||
val tableClass: KClass<*>, | ||
val configureTable: (CreateTableRequest) -> CreateTableRequest = { it } | ||
) { | ||
val tableName: String | ||
get() { | ||
val annotation = tableClass.findAnnotation<DynamoDBTable>() | ||
?: throw IllegalStateException("Expected @DynamoDBTable on $tableClass") | ||
return annotation.tableName | ||
} | ||
} |
Oops, something went wrong.