Skip to content
Permalink
Browse files
feat(spanner): add a database name getter to client (#4190)
  • Loading branch information
hengfengli committed Jun 3, 2021
1 parent 94485e6 commit 7fce29af404f0623b483ca6d6f2af4c726105fa6
Showing with 19 additions and 0 deletions.
  1. +6 −0 spanner/client.go
  2. +13 −0 spanner/client_test.go
@@ -82,6 +82,12 @@ type Client struct {
qo QueryOptions
}

// DatabaseName returns the full name of a database, e.g.,
// "projects/spanner-cloud-test/instances/foo/databases/foodb".
func (c *Client) DatabaseName() string {
return c.sc.database
}

// ClientConfig has configurations for the client.
type ClientConfig struct {
// NumChannels is the number of gRPC channels.
@@ -416,6 +416,19 @@ func TestClient_Single_QueryOptions(t *testing.T) {
}
}

func TestClient_ReturnDatabaseName(t *testing.T) {
t.Parallel()

_, client, teardown := setupMockedTestServer(t)
defer teardown()

got := client.DatabaseName()
want := "projects/[PROJECT]/instances/[INSTANCE]/databases/[DATABASE]"
if got != want {
t.Fatalf("Incorrect database name returned, got: %s, want: %s", got, want)
}
}

func testQueryOptions(t *testing.T, iter *RowIterator, server InMemSpannerServer, qo QueryOptions) {
defer iter.Stop()

0 comments on commit 7fce29a

Please sign in to comment.