mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 07:00:50 +08:00
File_Storage: Fix tests
I should really be running the tests more often. I'd clearly broken things and hadn't noticed.
This commit is contained in:
@ -7,18 +7,23 @@ import 'package:journal/note.dart';
|
|||||||
import 'package:journal/storage/file_storage.dart';
|
import 'package:journal/storage/file_storage.dart';
|
||||||
import 'package:journal/storage/serializers.dart';
|
import 'package:journal/storage/serializers.dart';
|
||||||
|
|
||||||
|
DateTime nowWithoutMicro() {
|
||||||
|
var dt = DateTime.now();
|
||||||
|
return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
group('FileStorage', () {
|
group('FileStorage', () {
|
||||||
var notes = [
|
var notes = [
|
||||||
Note(id: "1", body: "test", created: new DateTime.now()),
|
Note(id: "1", body: "test", created: nowWithoutMicro()),
|
||||||
Note(id: "2", body: "test2", created: new DateTime.now()),
|
Note(id: "2", body: "test2", created: nowWithoutMicro()),
|
||||||
];
|
];
|
||||||
|
|
||||||
final directory = Directory.systemTemp.createTemp('__storage_test__');
|
final directory = Directory.systemTemp.createTemp('__storage_test__');
|
||||||
final storage = FileStorage(
|
final storage = FileStorage(
|
||||||
getDirectory: () => directory,
|
getDirectory: () => directory,
|
||||||
noteSerializer: new JsonNoteSerializer(),
|
noteSerializer: new JsonNoteSerializer(),
|
||||||
fileNameGenerator: (Note note) => note.id,
|
fileNameGenerator: (Note note) => note.id + '.md',
|
||||||
);
|
);
|
||||||
|
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
@ -30,8 +35,8 @@ main() {
|
|||||||
var dir = await storage.saveNotes(notes);
|
var dir = await storage.saveNotes(notes);
|
||||||
expect(dir.listSync(recursive: true).length, 2);
|
expect(dir.listSync(recursive: true).length, 2);
|
||||||
|
|
||||||
expect(File(p.join(dir.path, "1")).existsSync(), isTrue);
|
expect(File(p.join(dir.path, "1.md")).existsSync(), isTrue);
|
||||||
expect(File(p.join(dir.path, "2")).existsSync(), isTrue);
|
expect(File(p.join(dir.path, "2.md")).existsSync(), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should load Notes from disk', () async {
|
test('Should load Notes from disk', () async {
|
||||||
|
Reference in New Issue
Block a user