I'm developing an open source project and we are using cloud spanner as an online db. I'm trying to use the Spanner Emulator in unit tests.
I can run test on emulator but I want to: When running the test, I hope gcloud emulators spanner start can be run automatically instead of manually starting. I want to recreate the database by loading the --ddl-file at the setup() period of each run. Is there some sample or reference on how to do it?
The open-source Liquibase integration for Cloud Spanner uses the Cloud Spanner emulator for testing, and starts it from code using a Docker test container: https://github.com/cloudspannerecosystem/liquibase-spanner/blob/d547be5d4fde0a71df62a7de543aa3e99472ecda/src/test/java/com/google/spanner/liquibase/TestHarness.java#L124
Those tests don't include any specific DDL-file that the emulator should use at startup, but it should be relatively easy to add that to the command that is being executed. You didn't indicate which programming language that you are using, but the open source testcontainers project has bindings for most popular languages (Java, Go, .NET, Python, Node.js, ...)