Skip to content

Commit

Permalink
spanner/spannertest: document using SPANNER_EMULATOR_HOST
Browse files Browse the repository at this point in the history
Updates #1181.

Change-Id: I369b2cbadff6f7434ea79e878a57b186359f47cd
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/43231
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
  • Loading branch information
dsymonds committed Jul 31, 2019
1 parent 32c4871 commit dc6be4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 8 additions & 0 deletions spanner/spannertest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ create a Server, and then connect to it with no security:
client, err := spanner.NewClient(ctx, db, option.WithGRPCConn(conn))
...
Alternatively, create a Server, then set the SPANNER_EMULATOR_HOST environment
variable and use the regular spanner.NewClient:
srv, err := spannertest.NewServer("localhost:0")
...
os.Setenv("SPANNER_EMULATOR_HOST", srv.Addr)
client, err := spanner.NewClient(ctx, db)
...
The same server also supports database admin operations for use with
the cloud.google.com/go/spanner/admin/database/apiv1 package.
*/
Expand Down
7 changes: 2 additions & 5 deletions spanner/spannertest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ func makeClient(t *testing.T) (*spanner.Client, *dbadmin.DatabaseAdminClient, fu
return client, adminClient, func() { client.Close(); adminClient.Close() }
}

// Unfortunately the Spanner client library does not permit insecure connections
// like other client libraries (providing an endpoint and grpc.WithInsecure fails
// because it uses transport.DialGRPC directly), so we need to manually construct the
// gRPC connection and provide it to the client library. This may bypass our ability
// to check some aspects of the connection pooling.
// Don't use SPANNER_EMULATOR_HOST because we need the raw connection for
// the database admin client anyway.

t.Logf("Using in-memory fake Spanner DB")
srv, err := NewServer("localhost:0")
Expand Down

0 comments on commit dc6be4b

Please sign in to comment.