Skip to content

Commit

Permalink
feat(spanner): add a database name getter to client (#4190)
Browse files Browse the repository at this point in the history
  • Loading branch information
hengfengli committed Jun 3, 2021
1 parent 94485e6 commit 7fce29a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spanner/client.go
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions spanner/client_test.go
Expand Up @@ -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()

Expand Down

0 comments on commit 7fce29a

Please sign in to comment.