firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Set "bucket" automatically from storageBucket #19

Closed deremer closed 5 years ago

deremer commented 6 years ago

When unit testing cloud storage triggered functions that need to download and manipulate the file (e.g., to create thumbnails), we need to use storage.makeObjectMetadata() to define a test image file to use. And, in order to make it work, we have to re-define our project "bucket" in every test like this:

FbTest.storage.makeObjectMetadata({
      name: 'unit_tests/Amaze.png',
      bucket: 'my-firebase-project-id.appspot.com',
      contentType: 'image/png'
});

Since, we already define the storageBucket when initializing the test library, it'd be preferred if the default value for "bucket" was automatically set. This would not only mean less code in tests, but also less opportunity for errors and confusion for people getting started with tests (it actually took me a bit of time to figure out what to do with "bucket" and "name", especially since all my images are in folders).

In fact, since Firebase projects only have one bucket, I don't know why a fb function unit test would ever need to specify one.

abeisgoat commented 5 years ago

Seems like a reasonable request. Will put in a PR.

deremer commented 5 years ago

Thanks @abehaskins

Also, to readers from the future, I'd like to amend my previous comment about Firebase projects only having one bucket. It's true there is a default bucket, but it's possible to have and access other storage buckets on GCP via firebase sdks: https://firebase.google.com/docs/storage/admin/start#use_custom_buckets