Merge branch 'main' into firestore-multi-dbs
diff --git a/firestore/client.go b/firestore/client.go
index 35d695a..3c2f7f5 100644
--- a/firestore/client.go
+++ b/firestore/client.go
@@ -96,11 +96,27 @@
 	c := &Client{
 		c:          vc,
 		projectID:  projectID,
-		databaseID: "(default)", // always "(default)", for now
+		databaseID: "(default)", // Default value is `(default)`
 	}
 	return c, nil
 }
 
+// NewClientWithDatabase creates a new Firestore client that accesses the
+// specified database.
+func NewClientWithDatabase(ctx context.Context, projectID string, databaseID string, opts ...option.ClientOption) (*Client, error) {
+	if databaseID == "" {
+		return nil, errors.New("firestore: databaseName was empty")
+	}
+
+	client, err := NewClient(ctx, projectID, opts...)
+	if err != nil {
+		return nil, err
+	}
+
+	client.databaseID = databaseID
+	return client, nil
+}
+
 func detectProjectID(ctx context.Context, opts ...option.ClientOption) (string, error) {
 	creds, err := transport.Creds(ctx, opts...)
 	if err != nil {
diff --git a/firestore/integration_test.go b/firestore/integration_test.go
index dfd7698..79e90ba 100644
--- a/firestore/integration_test.go
+++ b/firestore/integration_test.go
@@ -26,6 +26,7 @@
 	"reflect"
 	"runtime"
 	"sort"
+	"strings"
 	"testing"
 	"time"
 
@@ -1720,3 +1721,20 @@
 		t.Errorf("Unexpected number of documents across partitions: got %d, want %d", got, want)
 	}
 }
+
+func TestIntegration_NewDatabase(t *testing.T) {
+	t.Skip("firestore: integration: skipping new database test until deletion is possible.")
+
+	ctx := context.Background()
+	dbName := uid.NewSpace("integration-database", &uid.Options{}).New()
+	c, err := NewClientWithDatabase(ctx, iClient.projectID, dbName)
+
+	if err != nil {
+		t.Errorf("Can't create new database in project %s", iClient.projectID)
+	}
+
+	if !strings.Contains(c.databaseID, dbName) {
+		t.Errorf("new database not created:\nwanted database name %s\ngot database name %s", dbName, c.databaseID)
+	}
+	t.Log("finished the test")
+}