atn832 / firebase_storage_mocks Goto Github PK
View Code? Open in Web Editor NEWLicense: BSD 2-Clause "Simplified" License
License: BSD 2-Clause "Simplified" License
This package mocks many needed FirebaseStorage functions out of the box, though I find it lacks list
and listAll
implementation.
Executing this test:
test('uploaded file to cloud can be listed', () async {
final instance = MockFirebaseStorage();
var path = 'test/test/test/test';
final File testFile = await File('test/fixtures/test.jpg');
final Reference ref = instance.ref().child(path);
await ref.putFile(testFile);
final files = await ref.listAll();
expect(files.items.length == 1, true);
});
Gives the following error:
NoSuchMethodError: Class 'MockReference' has no instance method 'listAll' with matching arguments.
Receiver: Instance of 'MockReference'
Tried calling: listAll()
Found: listAll() => Future<ListResult>
dart:core Object.noSuchMethod
package:firebase_storage_mocks/src/mock_storage_reference.dart 123:56 MockReference.noSuchMethod
package:firebase_storage/src/reference.dart 91:22 MockReference.listAll
When I run the example code, the putFile method always returns null. I also tried using the putData method instead but it results in the same error which is:
NoSuchMethodError: The getter 'onComplete' was called on null.
Receiver: null
Tried calling: onComplete
Any help will be appreciated.
Thank you.
I've gone ahead and forked this repo and implemented getDownloadURL
within MockStorageReference
. It seems that there is no way, AFAIK, to construct a download url that is similar to an actual Firebase Storage download URL (https://firebasestorage.googleapis.com/v0/b/{your-application}.appspot.com/o/{url-encoded-path-name}?alt=media&token={your-token}
) so I have it returning a dummy value instead (https://firebasestorage.googleapis.com/{path}
). This dummy value could be updated so that _path
is url encoded when interpolated into the download URL path that the function returns. Also, there could probably also be a test written around this, but I didn't see any Mock Reference tests.
Let me know if you are interested in me creating a PR for my fork.
The current Usage example in README.md instantiates MockFirebaseStorage('someimage.png');
; however, MockFirebaseStorage
has zero parameters (though in example here it is given 'someimage.png'.)
I plan on creating a PR that fixes this and a few other items in usage example.
Do you mind if I ask why no web support, since firebase_storage
package has web support?
I know this mock package wouldn't support putFile(File file)
or writeToFile(File file)
, but neither does the the original firebase_storage
which it implements, so that seems consistent.
To complete #31.
I have code that checks for TaskState.error
and it would be grate of the storage mock would allow me to test this code. Thanks!
During my testing I also noticed, that the behavior for .child() is inconsistent with the actual CloudFirestore package. It doesn't add a "/" to the path. I also fixed that in the latest commit
Originally posted by @timcreatedit in #26 (comment)
The storage functions from google only return the path part with the fullPath function.
When using the storage.ref() function with the result of the reference.fullPath the gs:// prefix exists double.
So basically storage.ref(storage.ref("/demo.txt").fullPath).fullPath
should equal "/demo.txt"
FIrebase storage refernce mock should support the methods list
and listAll
Bucket seems to be hardcoded to some-bucket
.
This package is incompatible with cloud_firestore_mocks because of this error:
Because no versions of cloud_firestore_mocks match >0.8.0 <0.9.0 and cloud_firestore_mocks 0.8.0 depends on mockito ^5.0.0, cloud_firestore_mocks ^0.8.0 requires mockito ^5.0.0.
And because every version of firebase_storage_mocks depends on mockito ^4.1.0, cloud_firestore_mocks ^0.8.0 is incompatible with firebase_storage_mocks.
If I override the dependency to mockito ^5.0.0
, I get the next error:
Because firebase_storage_mocks >=0.2.0 depends on firebase_storage ^4.0.0 and my_app depends on firebase_storage ^8.0.0, firebase_storage_mocks >=0.2.0 is forbidden.
So it also seems to be incompatible with the current version of firebase_storage
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.