New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
firestore: Provide function to configure emulator #1978
Comments
Thanks for filing the issue and for your clear description! I know the |
Emulator boostrapping and lifecycle management is something that has recently come up for several languages and as such is going to be larger than any one client to be improved. I'll include this request in the discussion around the improvements. Related issues: |
See for initial discussion: #319 Fixes #319, #210. Relates to #190. Similar issues in other SDKs: googleapis/google-cloud-go#1978, firebase/firebase-admin-node#776.
For what it's worth, the emulator is a reasonably heavyweight and slow-starting Java process, I wouldn't want to run multiple, nor would I want to start a new one per test. Since the Firestore emulator accepts any project id and doesn't require authentication, I have a helper that picks a random project id (prefixed with the test name, for debugging), and clears the data for each project id before the test. It works great with parallel tests, subtests, etc. |
This is a reasonable point, have you considered using unique project ids per test (or per parallel group)? |
I'm no longer working on this project, but I don't see why that approach wouldn't work (maybe with the modification that, instead of random project IDs, you use an atomic counter to guarantee uniqueness). |
@joshlf In my case, the tests run in multiple subprocesses, and I didn't want to impose coordination. The project id used concatenates a prefix, name of current test, and a 64-bit random number. It's realistically never going to collide. |
If you look at the Firestore tests, you'll see that we use a |
Hi, I want to write a test using testcontainers-go and as you can see here java client already allows to set the host and port, which is a random port provided by testcontainers. Can we reconsider it and make it available in go client, please? |
Is your feature request related to a problem? Please describe.
I'm writing unit tests to exercise code which connects to Firestore. What would be really nice is to have an in-process mock for testing. However, barring that, it's sufficient to run the Firestore emulator as a subprocess, and connect to it from unit tests.
However, the only officially supported way to connect to an emulator is to set the
FIRESTORE_EMULATOR_HOST
environment variable. Even if I were to do something likeos.Setenv("FIRESTORE_EMULATOR_HOST", ...)
, that would mean that I couldn't run tests in parallel with different emulators, as the environment variable is global.What I've resorted to instead is to adapt the logic that is used internally here:
google-cloud-go/firestore/client.go
Lines 64 to 71 in 096c584
and here:
google-cloud-go/firestore/client.go
Lines 335 to 346 in 096c584
Describe the solution you'd like
I would like there to be a first-class API for creating a
*firestore.Client
which accepts an emulator address as an argument rather than by consultingFIRESTORE_EMULATOR_HOST
.The text was updated successfully, but these errors were encountered: