refactor: extract repo setup for tests

This commit is contained in:
Aleksey Kulikov 2021-09-23 16:35:05 +03:00
parent 10b9864219
commit 466f960c7b
26 changed files with 176 additions and 320 deletions

View file

@ -7,24 +7,18 @@ import 'helpers/util.dart';
void main() {
late Repository repo;
late Index index;
final tmpDir = '${Directory.systemTemp.path}/index_testrepo/';
late Directory tmpDir;
setUp(() async {
if (await Directory(tmpDir).exists()) {
await Directory(tmpDir).delete(recursive: true);
}
await copyRepo(
from: Directory('test/assets/testrepo/'),
to: await Directory(tmpDir).create(),
);
repo = Repository.open(tmpDir);
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path);
index = repo.index;
});
tearDown(() async {
index.free();
repo.free();
await Directory(tmpDir).delete(recursive: true);
await tmpDir.delete(recursive: true);
});
group('Index', () {
@ -136,7 +130,7 @@ void main() {
test('writes to disk', () {
expect(index.length, 4);
File('$tmpDir/new_file').createSync();
File('${tmpDir.path}/new_file').createSync();
index.add('new_file');
index.write();