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';
@ -43,6 +44,19 @@ void main() {
submodule.free();
});
test('throws when trying to lookup and submodule not found', () {
expect(
() => repo.lookupSubmodule('not/there'),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"no submodule named 'not/there'",
),
),
);
});
test('successfully inits and updates', () {
final submoduleFilePath = '${repo.workdir}$testSubmodule/master.txt';
expect(File(submoduleFilePath).existsSync(), false);
@ -62,6 +76,19 @@ void main() {
expect(File(submoduleFilePath).existsSync(), true);
});
test('throws when trying to update not initialized submodule', () {
expect(
() => repo.updateSubmodule(submodule: testSubmodule),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"submodule is not initialized",
),
),
);
});
test('successfully opens repository for a submodule', () {
final submodule = repo.lookupSubmodule(testSubmodule);
repo.initSubmodule(submodule: testSubmodule);
@ -81,6 +108,24 @@ void main() {
submodule.free();
});
test('throws when trying to open repository for not initialized submodule',
() {
final submodule = repo.lookupSubmodule(testSubmodule);
expect(
() => submodule.open(),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
contains("failed to resolve path"),
),
),
);
submodule.free();
});
test('successfully adds submodule', () {
final submodule = repo.addSubmodule(
url: submoduleUrl,
@ -96,6 +141,38 @@ void main() {
submodule.free();
});
test('throws when trying to add submodule with wrong url', () {
expect(
() => repo.addSubmodule(
url: 'https://wrong.url/',
path: 'test',
),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
'failed to resolve address for wrong.url: Name or service not known',
),
),
);
});
test('throws when trying to add submodule and error occurs', () {
expect(
() => Repository(nullptr).addSubmodule(
url: 'https://wrong.url/',
path: 'test',
),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'repo'",
),
),
);
});
test('successfully sets configuration values', () {
final submodule = repo.lookupSubmodule(testSubmodule);
expect(submodule.url, submoduleUrl);