Skip to content

Commit

Permalink
Merge pull request #19 from atn832/virtual-file-for-tests
Browse files Browse the repository at this point in the history
Use memory file system when running unit tests
  • Loading branch information
atn832 committed Jun 30, 2022
2 parents 254b0c3 + e4810ee commit 7b06d6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
file: ^6.1.2
pedantic: ^1.0.0
test: ^1.16.5
16 changes: 11 additions & 5 deletions test/firebase_storage_mocks_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:file/memory.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_storage_mocks/firebase_storage_mocks.dart';
import 'package:test/test.dart';
Expand All @@ -9,12 +10,10 @@ final filename = 'someimage.png';

void main() {
group('MockFirebaseStorage Tests', () {

test('Puts File', () async {
final storage = MockFirebaseStorage();
final storageRef = storage.ref().child(filename);
final image = File(filename);
final task = storageRef.putFile(image);
final task = storageRef.putFile(getFakeImageFile());
await task;

expect(
Expand All @@ -37,8 +36,7 @@ void main() {
test('Set, get and update metadata', () async {
final storage = MockFirebaseStorage();
final storageRef = storage.ref().child(filename);
final image = File(filename);
final task = storageRef.putFile(image);
final task = storageRef.putFile(getFakeImageFile());
await task;
await storageRef.updateMetadata(SettableMetadata(
cacheControl: 'public,max-age=300',
Expand All @@ -64,8 +62,16 @@ void main() {
));
final metadata2 = await storageRef.getMetadata();
expect(metadata2.cacheControl == 'max-age=60', true);

///Old informations persist over updates
expect(metadata2.contentType == 'image/jpeg', true);
});
});
}

File getFakeImageFile() {
var fs = MemoryFileSystem();
final image = fs.file(filename);
image.writeAsStringSync('contents');
return image;
}

0 comments on commit 7b06d6a

Please sign in to comment.