Skip to content

Instantly share code, notes, and snippets.

@ablx
Created January 2, 2023 12:25
Show Gist options
  • Save ablx/44a47523235bf2f3a4b63a4088d7945b to your computer and use it in GitHub Desktop.
Save ablx/44a47523235bf2f3a4b63a4088d7945b to your computer and use it in GitHub Desktop.
Spring use-firestore-in-datastore-mode workaround
testImplementation("org.testcontainers:testcontainers:1.17.6")
testImplementation("org.testcontainers:gcloud:1.17.6")
testImplementation("org.testcontainers:junit-jupiter:1.17.6")
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Import
import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.DynamicPropertyRegistry
import org.springframework.test.context.DynamicPropertySource
import org.testcontainers.containers.DatastoreEmulatorContainer
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers
import org.testcontainers.utility.DockerImageName
@SpringBootTest
@Testcontainers
@DirtiesContext
class DatastoreIntegrationTest {
companion object {
@Container
val datastoreEmulator: DatastoreEmulatorContainer = DatastoreEmulatorContainer(
DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:412.0.0-emulators")
)
.withFlags("--no-store-on-disk --use-firestore-in-datastore-mode")
.withLogConsumer { println(it.utf8String) }
@JvmStatic
@DynamicPropertySource
fun emulatorProperties(registry: DynamicPropertyRegistry) {
registry.add("spring.cloud.gcp.datastore.host") { "http://" + datastoreEmulator.emulatorEndpoint }
}
}
}
internal class FooTest : DatastoreIntegrationTest() {
// call the datastore here, everything will run in the container.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment