Skip to content
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

feat(spanner): add a database name getter to client #4190

Merged
merged 2 commits into from Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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