Created
January 2, 2023 12:25
-
-
Save ablx/44a47523235bf2f3a4b63a4088d7945b to your computer and use it in GitHub Desktop.
Spring use-firestore-in-datastore-mode workaround
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
testImplementation("org.testcontainers:testcontainers:1.17.6") | |
testImplementation("org.testcontainers:gcloud:1.17.6") | |
testImplementation("org.testcontainers:junit-jupiter:1.17.6") |
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
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 } | |
} | |
} | |
} |
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
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