test: add more tests for throws and their messages

This commit is contained in:
Aleksey Kulikov 2021-10-19 17:16:39 +03:00
parent d6eae1e9ed
commit 127849519d
80 changed files with 2741 additions and 1501 deletions

View file

@ -1,3 +1,4 @@
import 'dart:ffi';
import 'dart:io';
import 'package:test/test.dart';
import 'package:libgit2dart/libgit2dart.dart';
@ -27,6 +28,19 @@ void main() {
packbuilder.free();
});
test('throws when trying to initialize and error occurs', () {
expect(
() => PackBuilder(Repository(nullptr)),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'repo'",
),
),
);
});
test('successfully adds objects', () {
final packbuilder = PackBuilder(repo);
final odb = repo.odb;
@ -41,7 +55,24 @@ void main() {
packbuilder.free();
});
test('successfully adds objects recursively', () {
test('throws when trying to add object and error occurs', () {
final packbuilder = PackBuilder(repo);
expect(
() => packbuilder.add(Oid(nullptr)),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'oid'",
),
),
);
packbuilder.free();
});
test('successfully adds object recursively', () {
final packbuilder = PackBuilder(repo);
final oid = Oid.fromSHA(repo: repo, sha: 'f17d0d48');
@ -51,6 +82,23 @@ void main() {
packbuilder.free();
});
test('throws when trying to add object recursively and error occurs', () {
final packbuilder = PackBuilder(repo);
expect(
() => packbuilder.addRecursively(Oid(nullptr)),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'id'",
),
),
);
packbuilder.free();
});
test('successfully sets number of threads', () {
final packbuilder = PackBuilder(repo);
@ -105,6 +153,23 @@ void main() {
expect(writtenCount, 18);
});
test('throws when trying to write pack into invalid path', () {
final packbuilder = PackBuilder(repo);
expect(
() => packbuilder.write('invalid/path'),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
contains('failed to create temporary file'),
),
),
);
packbuilder.free();
});
test('returns string representation of PackBuilder object', () {
final packbuilder = PackBuilder(repo);
expect(packbuilder.toString(), contains('PackBuilder{'));