refactor!: use class names instead of aliases from Repository in tests (#37)

BREAKING CHANGE: move API methods related to diffing into Diff class
This commit is contained in:
Aleksey Kulikov 2022-01-25 12:05:34 +03:00 committed by GitHub
parent 3e1ece4e6f
commit 08cbe8a17f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 943 additions and 834 deletions

View file

@ -28,7 +28,7 @@ void main() {
group('Branch', () {
test('returns a list of all branches', () {
const branchesExpected = ['feature', 'master', 'origin/master'];
final branches = repo.branches;
final branches = Branch.list(repo: repo);
for (var i = 0; i < branches.length; i++) {
expect(branches[i].name, branchesExpected[i]);
@ -38,7 +38,7 @@ void main() {
test('returns a list of local branches', () {
const branchesExpected = ['feature', 'master'];
final branches = repo.branchesLocal;
final branches = Branch.list(repo: repo, type: GitBranch.local);
for (var i = 0; i < branches.length; i++) {
expect(branches[i].name, branchesExpected[i]);
@ -48,7 +48,7 @@ void main() {
test('returns a list of remote branches', () {
const branchesExpected = ['origin/master'];
final branches = repo.branchesRemote;
final branches = Branch.list(repo: repo, type: GitBranch.remote);
for (var i = 0; i < branches.length; i++) {
expect(branches[i].name, branchesExpected[i]);
@ -57,31 +57,37 @@ void main() {
});
test('throws when trying to return list and error occurs', () {
final nullRepo = Repository(nullptr);
expect(() => Branch.list(repo: nullRepo), throwsA(isA<LibGit2Error>()));
expect(
() => Branch.list(repo: Repository(nullptr)),
throwsA(isA<LibGit2Error>()),
);
});
test('returns a branch with provided name', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.target.sha, lastCommit.sha);
branch.free();
});
test('throws when provided name not found', () {
expect(
() => repo.lookupBranch(name: 'invalid'),
() => Branch.lookup(repo: repo, name: 'invalid'),
throwsA(isA<LibGit2Error>()),
);
expect(
() => repo.lookupBranch(name: 'origin/invalid', type: GitBranch.remote),
() => Branch.lookup(
repo: repo,
name: 'origin/invalid',
type: GitBranch.remote,
),
throwsA(isA<LibGit2Error>()),
);
});
test('checks if branch is current head', () {
final masterBranch = repo.lookupBranch(name: 'master');
final featureBranch = repo.lookupBranch(name: 'feature');
final masterBranch = Branch.lookup(repo: repo, name: 'master');
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
expect(masterBranch.isHead, true);
expect(featureBranch.isHead, false);
@ -99,8 +105,8 @@ void main() {
});
test('checks if branch is checked out', () {
final masterBranch = repo.lookupBranch(name: 'master');
final featureBranch = repo.lookupBranch(name: 'feature');
final masterBranch = Branch.lookup(repo: repo, name: 'master');
final featureBranch = Branch.lookup(repo: repo, name: 'feature');
expect(masterBranch.isCheckedOut, true);
expect(featureBranch.isCheckedOut, false);
@ -118,7 +124,7 @@ void main() {
});
test('returns name', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.name, 'master');
branch.free();
});
@ -129,7 +135,7 @@ void main() {
});
test('returns remote name of a remote-tracking branch', () {
final branch = repo.branchesRemote.first;
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
expect(branch.remoteName, 'origin');
branch.free();
});
@ -137,12 +143,12 @@ void main() {
test(
'throws when getting remote name of a remote-tracking branch and '
'error occurs', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(() => branch.remoteName, throwsA(isA<LibGit2Error>()));
});
test('returns upstream of a local branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
final upstream = branch.upstream;
expect(upstream.isRemote, true);
@ -153,17 +159,18 @@ void main() {
});
test('throws when trying to get upstream of a remote branch', () {
final branch = repo.branchesRemote.first;
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
expect(() => branch.upstream, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('sets upstream of a branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
var upstream = branch.upstream;
expect(upstream.name, 'refs/remotes/origin/master');
final ref = repo.createReference(
final ref = Reference.create(
repo: repo,
name: 'refs/remotes/origin/new',
target: 'refs/heads/master',
);
@ -178,7 +185,7 @@ void main() {
});
test('unsets upstream of a branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
final upstream = branch.upstream;
expect(upstream.name, 'refs/remotes/origin/master');
@ -190,7 +197,7 @@ void main() {
});
test('throws when trying to set upstream of a branch and error occurs', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(
() => branch.setUpstream('some/upstream'),
throwsA(isA<LibGit2Error>()),
@ -199,50 +206,53 @@ void main() {
});
test('returns upstream name of a local branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.upstreamName, 'refs/remotes/origin/master');
branch.free();
});
test('throws when trying to get upstream name of a branch and error occurs',
() {
final branch = repo.lookupBranch(name: 'feature');
final branch = Branch.lookup(repo: repo, name: 'feature');
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('returns upstream remote of a local branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.upstreamRemote, 'origin');
branch.free();
});
test('throws when trying to get upstream remote of a remote branch', () {
final branch = repo.branchesRemote.first;
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
expect(() => branch.upstreamName, throwsA(isA<LibGit2Error>()));
branch.free();
});
test('returns upstream merge of a local branch', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.upstreamMerge, 'refs/heads/master');
branch.free();
});
test('throws when trying to get upstream merge of a remote branch', () {
final branch = repo.branchesRemote.first;
final branch = Branch.list(repo: repo, type: GitBranch.remote).first;
expect(() => branch.upstreamMerge, throwsA(isA<LibGit2Error>()));
branch.free();
});
group('create()', () {
test('creates branch', () {
final commit = repo.lookupCommit(lastCommit);
final commit = Commit.lookup(repo: repo, oid: lastCommit);
final branch = Branch.create(
repo: repo,
name: 'testing',
target: commit,
);
final branches = Branch.list(repo: repo);
final branch = repo.createBranch(name: 'testing', target: commit);
final branches = repo.branches;
expect(repo.branches.length, 4);
expect(branches.length, 4);
expect(branch.target, lastCommit);
for (final branch in branches) {
@ -253,10 +263,10 @@ void main() {
});
test('throws when name already exists', () {
final commit = repo.lookupCommit(lastCommit);
final commit = Commit.lookup(repo: repo, oid: lastCommit);
expect(
() => repo.createBranch(name: 'feature', target: commit),
() => Branch.create(repo: repo, name: 'feature', target: commit),
throwsA(isA<LibGit2Error>()),
);
@ -264,14 +274,14 @@ void main() {
});
test('creates branch with force flag when name already exists', () {
final commit = repo.lookupCommit(lastCommit);
final branch = repo.createBranch(
final commit = Commit.lookup(repo: repo, oid: lastCommit);
final branch = Branch.create(
repo: repo,
name: 'feature',
target: commit,
force: true,
);
final localBranches = repo.branchesLocal;
final localBranches = Branch.list(repo: repo, type: GitBranch.local);
expect(localBranches.length, 2);
expect(branch.target, lastCommit);
@ -286,17 +296,17 @@ void main() {
group('delete()', () {
test('deletes branch', () {
repo.deleteBranch('feature');
Branch.delete(repo: repo, name: 'feature');
expect(
() => repo.lookupBranch(name: 'feature'),
() => Branch.lookup(repo: repo, name: 'feature'),
throwsA(isA<LibGit2Error>()),
);
});
test('throws when trying to delete current HEAD', () {
expect(
() => repo.deleteBranch('master'),
() => Branch.delete(repo: repo, name: 'master'),
throwsA(isA<LibGit2Error>()),
);
});
@ -304,13 +314,13 @@ void main() {
group('rename()', () {
test('renames branch', () {
repo.renameBranch(oldName: 'feature', newName: 'renamed');
final branch = repo.lookupBranch(name: 'renamed');
final branches = repo.branches;
Branch.rename(repo: repo, oldName: 'feature', newName: 'renamed');
final branch = Branch.lookup(repo: repo, name: 'renamed');
final branches = Branch.list(repo: repo);
expect(branches.length, 3);
expect(
() => repo.lookupBranch(name: 'feature'),
() => Branch.lookup(repo: repo, name: 'feature'),
throwsA(isA<LibGit2Error>()),
);
expect(branch.target, featureCommit);
@ -323,18 +333,23 @@ void main() {
test('throws when name already exists', () {
expect(
() => repo.renameBranch(oldName: 'feature', newName: 'master'),
() => Branch.rename(
repo: repo,
oldName: 'feature',
newName: 'master',
),
throwsA(isA<LibGit2Error>()),
);
});
test('renames branch with force flag when name already exists', () {
repo.renameBranch(
Branch.rename(
repo: repo,
oldName: 'master',
newName: 'feature',
force: true,
);
final branch = repo.lookupBranch(name: 'feature');
final branch = Branch.lookup(repo: repo, name: 'feature');
expect(branch.target, lastCommit);
@ -343,14 +358,18 @@ void main() {
test('throws when name is invalid', () {
expect(
() => repo.renameBranch(oldName: 'feature', newName: 'inv@{id'),
() => Branch.rename(
repo: repo,
oldName: 'feature',
newName: 'inv@{id',
),
throwsA(isA<LibGit2Error>()),
);
});
});
test('returns string representation of Branch object', () {
final branch = repo.lookupBranch(name: 'master');
final branch = Branch.lookup(repo: repo, name: 'master');
expect(branch.toString(), contains('Branch{'));
branch.free();
});