@@ -29,6 +29,7 @@ import (
2929 "testing"
3030 "time"
3131
32+ "cloud.google.com/go/firestore"
3233 "firebase.google.com/go/v4/messaging"
3334 "golang.org/x/oauth2"
3435 "golang.org/x/oauth2/google"
@@ -282,8 +283,20 @@ func TestFirestore(t *testing.T) {
282283 t .Fatal (err )
283284 }
284285
285- if c , err := app .Firestore (ctx ); c == nil || err != nil {
286- t .Errorf ("Firestore() = (%v, %v); want (auth, nil)" , c , err )
286+ c , err := app .Firestore (ctx )
287+ if c == nil || err != nil {
288+ t .Fatalf ("Firestore() = (%v, %v); want (auth, nil)" , c , err )
289+ }
290+
291+ // verify that the client is using the default database ID
292+
293+ doc := c .Doc ("foo/bar" )
294+ if doc == nil {
295+ t .Fatalf ("Doc() = nil; want doc" )
296+ }
297+
298+ if ! strings .Contains (doc .Path , firestore .DefaultDatabaseID ) {
299+ t .Fatalf ("Doc().Path = %q; want to contain %q" , doc .Path , firestore .DefaultDatabaseID )
287300 }
288301}
289302
@@ -338,6 +351,33 @@ func TestFirestoreWithNoProjectID(t *testing.T) {
338351 }
339352}
340353
354+ func TestFirestoreWithDatabaseID (t * testing.T ) {
355+ firestoreid := "my-awesome-firestore-db"
356+
357+ ctx := context .Background ()
358+ config := & Config {FirestoreID : firestoreid }
359+ app , err := NewApp (ctx , config , option .WithCredentialsFile ("testdata/service_account.json" ))
360+ if err != nil {
361+ t .Fatal (err )
362+ }
363+
364+ c , err := app .Firestore (ctx )
365+ if c == nil || err != nil {
366+ t .Fatalf ("Firestore() = (%v, %v); want (auth, nil)" , c , err )
367+ }
368+
369+ // verify that the client is using the default database ID
370+
371+ doc := c .Doc ("foo/bar" )
372+ if doc == nil {
373+ t .Fatalf ("Doc() = nil; want doc" )
374+ }
375+
376+ if ! strings .Contains (doc .Path , firestoreid ) {
377+ t .Fatalf ("Doc().Path = %q; want to contain %q" , doc .Path , firestore .DefaultDatabaseID )
378+ }
379+ }
380+
341381func TestInstanceID (t * testing.T ) {
342382 ctx := context .Background ()
343383 app , err := NewApp (ctx , nil , option .WithCredentialsFile ("testdata/service_account.json" ))
0 commit comments