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

@ -1,13 +1,10 @@
import 'dart:io';
import 'package:libgit2dart/libgit2dart.dart';
import 'helpers.dart';
import '../test/helpers/util.dart';
void main() async {
// Preparing example repository.
final tmpDir = '${Directory.systemTemp.path}/example_repo/';
await prepareRepo(tmpDir);
final tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
// Open system + global config file.
final config = Config.open();
@ -22,7 +19,7 @@ void main() async {
// Open config file at provided path.
// Exception is thrown if file not found.
try {
final repoConfig = Config.open('$tmpDir/.git/config');
final repoConfig = Config.open('${tmpDir.path}/.git/config');
print('\nAll entries of repo config:');
for (final entry in repoConfig) {
@ -57,5 +54,5 @@ void main() async {
}
// Removing example repository.
await disposeRepo(tmpDir);
await tmpDir.delete(recursive: true);
}

View file

@ -1,16 +0,0 @@
import 'dart:io';
import '../test/helpers/util.dart';
Future<void> prepareRepo(String path) async {
if (await Directory(path).exists()) {
await Directory(path).delete(recursive: true);
}
await copyRepo(
from: Directory('test/assets/testrepo/'),
to: await Directory(path).create(),
);
}
Future<void> disposeRepo(String path) async {
await Directory(path).delete(recursive: true);
}

View file

@ -1,14 +1,12 @@
import 'dart:io';
import 'package:libgit2dart/libgit2dart.dart';
import 'helpers.dart';
import '../test/helpers/util.dart';
void main() async {
// Preparing example repository.
final tmpDir = '${Directory.systemTemp.path}/example_repo/';
await prepareRepo(tmpDir);
final tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
final repo = Repository.open(tmpDir);
final repo = Repository.open(tmpDir.path);
// Get list of repo's references.
print('Repository references: ${repo.references.list()}');
@ -39,5 +37,5 @@ void main() async {
repo.free();
// Removing example repository.
await disposeRepo(tmpDir);
await tmpDir.delete(recursive: true);
}