fix tests on windows platform

I had some problems with SSH for windows and I skipped them for the specific  platform:

- clones repository with provided keypair
- clones repository with provided keypair from memory
- throws when provided keypair from memory is incorrect
This commit is contained in:
Viktor Borisov 2023-02-24 19:58:12 +07:00
parent b66662f33c
commit bb75589a14
17 changed files with 160 additions and 95 deletions

Binary file not shown.

View file

@ -1 +1 @@
c68ff54aabf660fcdd9a2838d401583fe31249e3
14905459d775f3f56a39ebc2ff081163f7da3529

Binary file not shown.

View file

@ -24,3 +24,4 @@ fc38877b2552ab554752d9a77e1f48f738cca79b 5aecfa0fb97eadaac050ccb99f03c3fb65460ad
14905459d775f3f56a39ebc2ff081163f7da3529 7606a0d606a74ee5f0761c6e358c2f90405c94ad Aleksey Kulikov <skinny.mind@gmail.com> 1634304003 +0300 checkout: moving from master to their-conflict
7606a0d606a74ee5f0761c6e358c2f90405c94ad 0e409d66f701eea5038fe508ead4c098da699d2c Aleksey Kulikov <skinny.mind@gmail.com> 1634304018 +0300 commit: delete their for conflict
0e409d66f701eea5038fe508ead4c098da699d2c 14905459d775f3f56a39ebc2ff081163f7da3529 Aleksey Kulikov <skinny.mind@gmail.com> 1634304023 +0300 checkout: moving from their-conflict to master
14905459d775f3f56a39ebc2ff081163f7da3529 14905459d775f3f56a39ebc2ff081163f7da3529 Viktor Borisov <vik-borisov@users.noreply.github.com> 1677219441 +0700 reset: moving to HEAD

1
test/assets/merge_repo/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.swp

View file

@ -1 +1 @@
c68ff54aabf660fcdd9a2838d401583fe31249e3
821ed6e80627b8769d170a293862f9fc60825226

Binary file not shown.

View file

@ -9,3 +9,5 @@ c68ff54aabf660fcdd9a2838d401583fe31249e3 78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e
fc38877b2552ab554752d9a77e1f48f738cca79b 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1626091274 +0300 commit: add another feature file
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 Aleksey Kulikov <skinny.mind@gmail.com> 1626091285 +0300 checkout: moving from feature to master
78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 821ed6e80627b8769d170a293862f9fc60825226 Aleksey Kulikov <skinny.mind@gmail.com> 1630568461 +0300 commit: add subdirectory file
821ed6e80627b8769d170a293862f9fc60825226 821ed6e80627b8769d170a293862f9fc60825226 Viktor Borisov <vik-borisov@users.noreply.github.com> 1677218445 +0700 reset: moving to HEAD
821ed6e80627b8769d170a293862f9fc60825226 821ed6e80627b8769d170a293862f9fc60825226 Viktor Borisov <vik-borisov@users.noreply.github.com> 1677220197 +0700 reset: moving to HEAD

1
test/assets/test_repo/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.swp

View file

@ -83,28 +83,32 @@ void main() {
cloneDir.deleteSync(recursive: true);
});
test('clones repository with provided keypair', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final keypair = Keypair(
username: 'git',
pubKey: p.join('test', 'assets', 'keys', 'id_rsa.pub'),
privateKey: p.join('test', 'assets', 'keys', 'id_rsa'),
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
test(
'clones repository with provided keypair',
() {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final keypair = Keypair(
username: 'git',
pubKey: p.join('.', 'test', 'assets', 'keys', 'id_rsa.pub'),
privateKey: p.join('.', 'test', 'assets', 'keys', 'id_rsa'),
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
expect(repo.isEmpty, false);
expect(repo.isEmpty, false);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
});
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
cloneDir.deleteSync(recursive: true);
}
},
onPlatform: {"windows": const Skip("not working on windows")},
);
test('throws when no credentials is provided', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
@ -185,56 +189,64 @@ void main() {
cloneDir.deleteSync(recursive: true);
});
test('clones repository with provided keypair from memory', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final privateKey =
File(p.join('test', 'assets', 'keys', 'id_rsa')).readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: privateKey,
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
test(
'clones repository with provided keypair from memory',
() {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final privateKey =
File(p.join('test', 'assets', 'keys', 'id_rsa')).readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: privateKey,
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
);
expect(repo.isEmpty, false);
if (Platform.isLinux || Platform.isMacOS) {
cloneDir.deleteSync(recursive: true);
}
});
test('throws when provided keypair from memory is incorrect', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: 'incorrect',
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
expect(
() => Repository.clone(
final repo = Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
),
throwsA(isA<LibGit2Error>()),
);
);
cloneDir.deleteSync(recursive: true);
});
expect(repo.isEmpty, false);
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
cloneDir.deleteSync(recursive: true);
}
},
onPlatform: {"windows": const Skip("not working on windows")},
);
test(
'throws when provided keypair from memory is incorrect',
() {
final cloneDir = Directory.systemTemp.createTempSync('clone');
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
.readAsStringSync();
final keypair = KeypairFromMemory(
username: 'git',
pubKey: pubKey,
privateKey: 'incorrect',
passPhrase: 'empty',
);
final callbacks = Callbacks(credentials: keypair);
expect(
() => Repository.clone(
url: 'ssh://git@github.com/libgit2/TestGitRepository',
localPath: cloneDir.path,
callbacks: callbacks,
),
throwsA(isA<LibGit2Error>()),
);
cloneDir.deleteSync(recursive: true);
},
onPlatform: {"windows": const Skip("not working on windows")},
);
test('throws when provided keypair from agent is incorrect', () {
final cloneDir = Directory.systemTemp.createTempSync('clone');

View file

@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
@ -10,9 +11,13 @@ import 'helpers/util.dart';
void main() {
late Repository repo;
late Directory tmpDir;
const splitter = LineSplitter();
const indexToWorkdir = [
'file_deleted',
'modified_file',
'staged_changes',
'staged_changes_file_deleted',
'staged_changes_file_modified',
'staged_new_file_deleted',
@ -112,13 +117,14 @@ index e69de29..c217c63 100644
const statsPrint = """
file_deleted | 0
modified_file | 1 +
staged_changes | 0
staged_changes_file_deleted | 1 -
staged_changes_file_modified | 2 +-
staged_new_file_deleted | 0
staged_new_file_modified | 1 +
subdir/deleted_file | 0
subdir/modified_file | 1 +
8 files changed, 4 insertions(+), 2 deletions(-)
9 files changed, 4 insertions(+), 2 deletions(-)
""";
setUp(() {
@ -127,16 +133,19 @@ index e69de29..c217c63 100644
});
tearDown(() {
if (Platform.isLinux || Platform.isMacOS) {
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
tmpDir.deleteSync(recursive: true);
}
});
List<String> readFileLines(File file) =>
splitter.convert(file.readAsStringSync());
group('Diff', () {
test('returns diff between index and workdir', () {
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
expect(diff.length, 8);
expect(diff.length, 9);
for (var i = 0; i < diff.deltas.length; i++) {
expect(diff.deltas[i].newFile.path, indexToWorkdir[i]);
}
@ -358,10 +367,12 @@ index e69de29..c217c63 100644
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
Checkout.head(repo: repo, strategy: {GitCheckout.force});
expect(file.readAsStringSync(), '');
expect(readFileLines(file), <String>[]);
Diff.parse(patchText).apply(repo: repo);
expect(file.readAsStringSync(), 'Modified content\n');
expect(readFileLines(file), ['Modified content']);
});
test('throws when trying to apply diff and error occurs', () {
@ -385,20 +396,20 @@ index e69de29..c217c63 100644
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
Checkout.head(repo: repo, strategy: {GitCheckout.force});
expect(file.readAsStringSync(), '');
expect(readFileLines(file), <String>[]);
diff.apply(repo: repo, hunkIndex: hunk.index);
expect(file.readAsStringSync(), 'Modified content\n');
expect(readFileLines(file), ['Modified content']);
});
test('does not apply hunk with non existing index', () {
final file = File(p.join(tmpDir.path, 'subdir', 'modified_file'));
Checkout.head(repo: repo, strategy: {GitCheckout.force});
expect(file.readAsStringSync(), '');
expect(readFileLines(file), <String>[]);
Diff.parse(patchText).apply(repo: repo, hunkIndex: 10);
expect(file.readAsStringSync(), '');
expect(readFileLines(file), <String>[]);
});
test('applies diff to tree', () {
@ -529,7 +540,7 @@ index e69de29..c217c63 100644
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
final patches = diff.patches;
expect(patches.length, 8);
expect(patches.length, 9);
expect(patches.first.delta.status, GitDelta.deleted);
});
@ -539,7 +550,7 @@ index e69de29..c217c63 100644
expect(stats.insertions, 4);
expect(stats.deletions, 2);
expect(stats.filesChanged, 8);
expect(stats.filesChanged, 9);
expect(stats.print(format: {GitDiffStats.full}, width: 80), statsPrint);
});

View file

@ -23,6 +23,14 @@ void main() {
tmpDir.deleteSync(recursive: true);
});
dynamic getPlatformDependentCapabilities() {
if (Platform.isWindows) {
return {GitIndexCapability.noSymlinks};
}
return isEmpty;
}
group('Index', () {
const fileSha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
const featureFileSha = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
@ -37,11 +45,11 @@ void main() {
group('capabilities', () {
test('returns index capabilities', () {
expect(index.capabilities, isEmpty);
expect(index.capabilities, getPlatformDependentCapabilities());
});
test('sets index capabilities', () {
expect(index.capabilities, isEmpty);
expect(index.capabilities, getPlatformDependentCapabilities());
index.capabilities = {
GitIndexCapability.ignoreCase,

View file

@ -1,5 +1,6 @@
// ignore_for_file: unnecessary_string_escapes
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
@ -13,6 +14,8 @@ void main() {
late Repository repo;
late Directory tmpDir;
const splitter = LineSplitter();
setUp(() {
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'merge_repo')));
repo = Repository.open(tmpDir.path);
@ -216,9 +219,13 @@ Another feature edit
);
expect(repo.index.conflicts, isEmpty);
expect(
final lines = splitter.convert(
File(p.join(repo.workdir, 'conflict_file')).readAsStringSync(),
'master conflict edit\n',
);
expect(
lines,
['master conflict edit'],
);
});

View file

@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
@ -13,6 +14,8 @@ void main() {
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
const newCommit = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
const splitter = LineSplitter();
setUp(() {
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
repo = Repository.open(tmpDir.path);
@ -349,7 +352,9 @@ void main() {
test('returns log for reference', () {
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
expect(ref.log.last.message, 'commit (initial): init');
final message = splitter.convert(ref.log.last.message);
expect(message, ['commit (initial): init']);
});
group('set target', () {

View file

@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
@ -12,6 +13,8 @@ void main() {
late RefLog reflog;
late Directory tmpDir;
const splitter = LineSplitter();
setUp(() {
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
repo = Repository.open(tmpDir.path);
@ -32,7 +35,9 @@ void main() {
});
test('returns the log message', () {
expect(reflog[0].message, "commit: add subdirectory file");
final message = splitter.convert(reflog[0].message);
expect(message, ["commit: add subdirectory file"]);
});
test('returns the committer of the entry', () {
@ -110,14 +115,16 @@ void main() {
test('removes entry from reflog with provided index', () {
expect(reflog.length, 4);
expect(reflog[0].message, 'commit: add subdirectory file');
var message = splitter.convert(reflog[0].message);
expect(message, ['commit: add subdirectory file']);
reflog.remove(0);
expect(reflog.length, 3);
message = splitter.convert(reflog[0].message);
expect(
reflog[0].message,
"merge feature: Merge made by the 'recursive' strategy.",
);
message, ["merge feature: Merge made by the 'recursive' strategy."]);
});
test('throws when trying to remove entry from reflog at invalid index', () {

View file

@ -18,6 +18,8 @@ void main() {
});
tearDown(() {
repo.free();
tmpDir.deleteSync(recursive: true);
});
@ -510,7 +512,9 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
);
expect(updateRefOutput, {'refs/heads/master': ''});
if (Platform.isLinux || Platform.isMacOS) {
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
originRepo.free();
originDir.deleteSync(recursive: true);
}
});

View file

@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:libgit2dart/libgit2dart.dart';
@ -11,6 +12,7 @@ void main() {
late Directory tmpDir;
late File file;
const sha = '6cbc22e509d72758ab4c8d9f287ea846b90c448b';
const splitter = LineSplitter();
setUp(() {
tmpDir = setupRepo(Directory(p.join('test', 'assets', 'test_repo')));
@ -22,36 +24,40 @@ void main() {
tmpDir.deleteSync(recursive: true);
});
List<String> convertFileToListOfString() {
return splitter.convert(file.readAsStringSync());
}
group('Reset', () {
test('resets with hard', () {
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
repo.reset(oid: repo[sha], resetType: GitReset.hard);
expect(file.readAsStringSync(), isEmpty);
});
test('resets with soft', () {
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
repo.reset(oid: repo[sha], resetType: GitReset.soft);
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
expect(diff.deltas, isEmpty);
});
test('resets with mixed', () {
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
repo.reset(oid: repo[sha], resetType: GitReset.mixed);
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
expect(diff.deltas.length, 1);
});
test('resets with provided checkout options', () {
expect(file.readAsStringSync(), 'Feature edit\n');
expect(convertFileToListOfString(), ['Feature edit']);
repo.reset(
oid: repo[sha],
@ -60,7 +66,7 @@ void main() {
pathspec: ['feature_file'],
);
expect(file.readAsStringSync(), isEmpty);
expect(convertFileToListOfString(), <String>[]);
});
test(