@@ -29,6 +29,7 @@ import (
29
29
"testing"
30
30
"time"
31
31
32
+ "cloud.google.com/go/firestore"
32
33
"firebase.google.com/go/v4/messaging"
33
34
"golang.org/x/oauth2"
34
35
"golang.org/x/oauth2/google"
@@ -282,8 +283,20 @@ func TestFirestore(t *testing.T) {
282
283
t .Fatal (err )
283
284
}
284
285
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 overridden 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 )
287
300
}
288
301
}
289
302
@@ -338,6 +351,33 @@ func TestFirestoreWithNoProjectID(t *testing.T) {
338
351
}
339
352
}
340
353
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
+
341
381
func TestInstanceID (t * testing.T ) {
342
382
ctx := context .Background ()
343
383
app , err := NewApp (ctx , nil , option .WithCredentialsFile ("testdata/service_account.json" ))
0 commit comments