Repository navigation
Allow specifying Spanner emulator host via Config - #165
Open
TangoEnSkai wants to merge 1 commit into
Open
TangoEnSkai wants to merge 1 commit into
TangoEnSkai wants to merge 1 commit into
Conversation
Add an EmulatorHost field to spanner.Config so that library users can connect to a Cloud Spanner emulator without setting the process-wide SPANNER_EMULATOR_HOST environment variable. When set, the client options mirror what the Cloud Spanner client libraries build from SPANNER_EMULATOR_HOST (passthrough endpoint, insecure gRPC transport, no authentication), and CredentialsFile is ignored since the emulator takes no credentials.
Contributor
Author
|
@kazegusuri you mentioned in #73 that a PR for this would be welcome — the original reporter never followed up, so here it is. The implementation mirrors the client libraries' own SPANNER_EMULATOR_HOST wiring. PTAL when you have a moment. |
Contributor
Author
|
Following up on the Config option for the Spanner emulator host: the PR is still mergeable, with tests, security scan, and CLA checks passing. @kazegusuri could you review the approach when convenient, or let me know if you would prefer any changes? Thanks! |
sinmetal
self-requested a review
September 29, 2026 08:17
Collaborator
|
@TangoEnSkai Thank you. I have merged #164 first, so could you please resolve the conflicts? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
close #73
When wrench is used as a library, the only way to point it at a Cloud Spanner emulator today is the
SPANNER_EMULATOR_HOSTenvironment variable. As the issue notes, callingos.Setenvfrom test code is process-wide and racy, which is exactly the situation where an emulator is most useful. @kazegusuri welcomed a PR for this in the issue thread; the original reporter never followed up, so here it is.What
EmulatorHostfield tospanner.Config.NewClientappends the same three client options that the Cloud Spanner client libraries build fromSPANNER_EMULATOR_HOST(seespanner.NewClientWithConfigand the admin client'sinit.gohook): apassthrough:///endpoint with the scheme stripped, an insecure gRPC transport, andoption.WithoutAuthentication().CredentialsFileis ignored whenEmulatorHostis set — the emulator takes no credentials, and combiningWithCredentialsFilewithWithoutAuthenticationwould fail dial-settings validation.TestEmulatorClientOptions(pure unit test) pins the endpoint normalization forhttp://,https://, andpassthrough:///prefixes.TestNewClientWithEmulatorHostConfig(emulator integration test) clearsSPANNER_EMULATOR_HOSTviat.Setenvand verifies that both the data client and the admin client reach the emulator throughConfig.EmulatorHostalone (CreateDatabase→EnsureMigrationTable→DropDatabase).Why
The field mirrors the client libraries' own emulator wiring rather than inventing a new path, so behaviour stays identical to
SPANNER_EMULATOR_HOST— including the scheme-stripping regex. Existing behaviour is unchanged whenEmulatorHostis empty. The new options are appended afterConfig.ClientOptions, consistent with the documented "config fields override ClientOptions" ordering already used byCredentialsFile.Completion Criteria
go build ./...,go vet ./...,gofmt -l .cleanTestEmulatorClientOptionspasses locally (no emulator needed)TestNewClientWithEmulatorHostConfigruns undermake test)