mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
test(repository): divide groups into different files
This commit is contained in:
parent
5680fd8674
commit
ec8ff24e89
3 changed files with 374 additions and 369 deletions
117
test/repository_empty_test.dart
Normal file
117
test/repository_empty_test.dart
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late Repository repo;
|
||||||
|
|
||||||
|
group('Repository.open', () {
|
||||||
|
test('throws when repository isn\'t found at provided path', () {
|
||||||
|
expect(
|
||||||
|
() => Repository.open(''),
|
||||||
|
throwsA(isA<LibGit2Error>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('empty bare', () {
|
||||||
|
setUp(() {
|
||||||
|
repo = Repository.open('test/assets/empty_bare.git');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
repo.free();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('opens successfully', () {
|
||||||
|
expect(repo, isA<Repository>());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if it is bare', () {
|
||||||
|
expect(repo.isBare, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns path to the repository', () {
|
||||||
|
expect(
|
||||||
|
repo.path,
|
||||||
|
'${Directory.current.path}/test/assets/empty_bare.git/',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns path to root directory for the repository', () {
|
||||||
|
expect(
|
||||||
|
repo.commonDir,
|
||||||
|
'${Directory.current.path}/test/assets/empty_bare.git/',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns empty string as path of the working directory', () {
|
||||||
|
expect(repo.workdir, '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('empty standard', () {
|
||||||
|
setUp(() {
|
||||||
|
repo = Repository.open('test/assets/empty_standard/.gitdir/');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
repo.free();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('opens standart repository from working directory successfully', () {
|
||||||
|
expect(repo, isA<Repository>());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns path to the repository', () {
|
||||||
|
expect(
|
||||||
|
repo.path,
|
||||||
|
'${Directory.current.path}/test/assets/empty_standard/.gitdir/',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns path to parent repo\'s .git folder for the repository', () {
|
||||||
|
expect(
|
||||||
|
repo.commonDir,
|
||||||
|
'${Directory.current.path}/test/assets/empty_standard/.gitdir/',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if it is empty', () {
|
||||||
|
expect(repo.isEmpty, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if head is detached', () {
|
||||||
|
expect(repo.isHeadDetached, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if branch is unborn', () {
|
||||||
|
expect(repo.isBranchUnborn, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('successfully sets identity ', () {
|
||||||
|
repo.setIdentity(name: 'name', email: 'email@email.com');
|
||||||
|
expect(repo.identity, {'name': 'email@email.com'});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('successfully unsets identity', () {
|
||||||
|
repo.setIdentity(name: null, email: null);
|
||||||
|
expect(repo.identity, isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if shallow clone', () {
|
||||||
|
expect(repo.isShallow, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('checks if linked work tree', () {
|
||||||
|
expect(repo.isWorktree, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns path to working directory', () {
|
||||||
|
expect(
|
||||||
|
repo.workdir,
|
||||||
|
'${Directory.current.path}/test/assets/empty_standard/',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
35
test/repository_init_test.dart
Normal file
35
test/repository_init_test.dart
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late Repository repo;
|
||||||
|
final initDir = Directory('${Directory.systemTemp.path}/init_repo');
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
if (await initDir.exists()) {
|
||||||
|
await initDir.delete(recursive: true);
|
||||||
|
} else {
|
||||||
|
await initDir.create();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
repo.free();
|
||||||
|
await initDir.delete(recursive: true);
|
||||||
|
});
|
||||||
|
group('Repository.init', () {
|
||||||
|
test('successfully creates new bare repo at provided path', () {
|
||||||
|
repo = Repository.init(initDir.path, isBare: true);
|
||||||
|
expect(repo.path, '${initDir.path}/');
|
||||||
|
expect(repo.isBare, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('successfully creates new standard repo at provided path', () {
|
||||||
|
repo = Repository.init(initDir.path);
|
||||||
|
expect(repo.path, '${initDir.path}/.git/');
|
||||||
|
expect(repo.isBare, false);
|
||||||
|
expect(repo.isEmpty, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -5,156 +5,11 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'helpers/util.dart';
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('Repository', () {
|
|
||||||
late Repository repo;
|
late Repository repo;
|
||||||
test('throws when repository isn\'t found at provided path', () {
|
late Directory tmpDir;
|
||||||
expect(
|
|
||||||
() => Repository.open(''),
|
|
||||||
throwsA(isA<LibGit2Error>()),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('.init()', () {
|
|
||||||
final initDir = Directory('${Directory.systemTemp.path}/init_repo');
|
|
||||||
|
|
||||||
setUp(() async {
|
|
||||||
if (await initDir.exists()) {
|
|
||||||
await initDir.delete(recursive: true);
|
|
||||||
} else {
|
|
||||||
await initDir.create();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tearDown(() async {
|
|
||||||
repo.free();
|
|
||||||
await initDir.delete(recursive: true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('successfully creates new bare repo at provided path', () {
|
|
||||||
repo = Repository.init(initDir.path, isBare: true);
|
|
||||||
expect(repo.path, '${initDir.path}/');
|
|
||||||
expect(repo.isBare, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('successfully creates new standard repo at provided path', () {
|
|
||||||
repo = Repository.init(initDir.path);
|
|
||||||
expect(repo.path, '${initDir.path}/.git/');
|
|
||||||
expect(repo.isBare, false);
|
|
||||||
expect(repo.isEmpty, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('empty', () {
|
|
||||||
group('bare', () {
|
|
||||||
setUp(() {
|
|
||||||
repo = Repository.open('test/assets/empty_bare.git');
|
|
||||||
});
|
|
||||||
|
|
||||||
tearDown(() {
|
|
||||||
repo.free();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('opens successfully', () {
|
|
||||||
expect(repo, isA<Repository>());
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if it is bare', () {
|
|
||||||
expect(repo.isBare, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns path to the repository', () {
|
|
||||||
expect(
|
|
||||||
repo.path,
|
|
||||||
'${Directory.current.path}/test/assets/empty_bare.git/',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns path to root directory for the repository', () {
|
|
||||||
expect(
|
|
||||||
repo.commonDir,
|
|
||||||
'${Directory.current.path}/test/assets/empty_bare.git/',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns empty string as path of the working directory', () {
|
|
||||||
expect(repo.workdir, '');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('standard', () {
|
|
||||||
setUp(() {
|
|
||||||
repo = Repository.open('test/assets/empty_standard/.gitdir/');
|
|
||||||
});
|
|
||||||
|
|
||||||
tearDown(() {
|
|
||||||
repo.free();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('opens standart repository from working directory successfully',
|
|
||||||
() {
|
|
||||||
expect(repo, isA<Repository>());
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns path to the repository', () {
|
|
||||||
expect(
|
|
||||||
repo.path,
|
|
||||||
'${Directory.current.path}/test/assets/empty_standard/.gitdir/',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns path to parent repo\'s .git folder for the repository',
|
|
||||||
() {
|
|
||||||
expect(
|
|
||||||
repo.commonDir,
|
|
||||||
'${Directory.current.path}/test/assets/empty_standard/.gitdir/',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if it is empty', () {
|
|
||||||
expect(repo.isEmpty, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if head is detached', () {
|
|
||||||
expect(repo.isHeadDetached, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if branch is unborn', () {
|
|
||||||
expect(repo.isBranchUnborn, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('successfully sets identity ', () {
|
|
||||||
repo.setIdentity(name: 'name', email: 'email@email.com');
|
|
||||||
expect(repo.identity, {'name': 'email@email.com'});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('successfully unsets identity', () {
|
|
||||||
repo.setIdentity(name: null, email: null);
|
|
||||||
expect(repo.identity, isEmpty);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if shallow clone', () {
|
|
||||||
expect(repo.isShallow, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks if linked work tree', () {
|
|
||||||
expect(repo.isWorktree, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns path to working directory', () {
|
|
||||||
expect(
|
|
||||||
repo.workdir,
|
|
||||||
'${Directory.current.path}/test/assets/empty_standard/',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('testrepo', () {
|
|
||||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||||
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
||||||
|
|
||||||
late Directory tmpDir;
|
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
repo = Repository.open(tmpDir.path);
|
repo = Repository.open(tmpDir.path);
|
||||||
|
@ -165,6 +20,7 @@ void main() {
|
||||||
await tmpDir.delete(recursive: true);
|
await tmpDir.delete(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('Repository', () {
|
||||||
test('returns config for repository', () {
|
test('returns config for repository', () {
|
||||||
final config = repo.config;
|
final config = repo.config;
|
||||||
expect(
|
expect(
|
||||||
|
@ -220,8 +76,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successfully sets working directory', () {
|
test('successfully sets working directory', () {
|
||||||
final tmpWorkDir =
|
final tmpWorkDir = Directory('${Directory.systemTemp.path}/tmp_work_dir');
|
||||||
Directory('${Directory.systemTemp.path}/tmp_work_dir');
|
|
||||||
tmpWorkDir.createSync();
|
tmpWorkDir.createSync();
|
||||||
|
|
||||||
repo.setWorkdir(tmpWorkDir.path);
|
repo.setWorkdir(tmpWorkDir.path);
|
||||||
|
@ -278,8 +133,7 @@ void main() {
|
||||||
newBlob.free();
|
newBlob.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('successfully creates new blob from file at provided relative path',
|
||||||
'successfully creates new blob from file at provided relative path',
|
|
||||||
() {
|
() {
|
||||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||||
final newBlob = repo[oid.sha] as Blob;
|
final newBlob = repo[oid.sha] as Blob;
|
||||||
|
@ -383,5 +237,4 @@ void main() {
|
||||||
config.free();
|
config.free();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue