Skip to content

Commit

Permalink
Fix action issue (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrath committed Jun 22, 2021
1 parent 94a214b commit 0deb12f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions test/5.repo.commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ async function repoTest(t, commondirInside: boolean) {
await Repository.initExt(repoPath, { commondir: `${commondir}.external-snow` });
}

let howManyCharsAreEqualInHash = 0;

const firstCommitMessage = 'Add Foo';
const secondCommitMessage = 'Delete Foo';
await Repository.open(repoPath)
Expand All @@ -45,6 +47,14 @@ async function repoTest(t, commondirInside: boolean) {
const file2 = await createRandomFile(foopath2, 2048);
index.addFiles([file2.filepath]);

if (file1.filehash.substr(0, 4) === file2.filehash.substr(0, 4)) {
howManyCharsAreEqualInHash = 4;
} else if (file1.filehash.substr(0, 2) === file2.filehash.substr(0, 2)) {
howManyCharsAreEqualInHash = 2;
} else {
howManyCharsAreEqualInHash = 0;
}

return index.writeFiles();
}).then(() => repo.createCommit(repo.getFirstIndex(), firstCommitMessage))
.then((commit: Commit) => {
Expand All @@ -59,9 +69,24 @@ async function repoTest(t, commondirInside: boolean) {

return osWalk(repo.workdir(), OSWALK.DIRS | OSWALK.FILES | OSWALK.HIDDEN | OSWALK.BROWSE_REPOS);
})
.then((dirItems: DirItem[]) => {
.then(async (dirItems: DirItem[]) => {
if (commondirInside) {
t.is(dirItems.length, 24, 'expect 24 items');
// Two random files can generate hashes where the first 2 or 4 digits are equal.
// Depending on the situation, we expect either 22, 23 or 24 items since we might have fewer
// directories in the object database

// eslint-disable-next-line default-case
switch (howManyCharsAreEqualInHash) {
case 4: // if 4-digits of hash are equal, we have 2 directories less
t.is(dirItems.length, 22, 'expect 22 items');
break;
case 2: // if 2-digits of hash are equal, we have 1 directory less
t.is(dirItems.length, 23, 'expect 23 items');
break;
case 0: // by default we expect 24 items
t.is(dirItems.length, 24, 'expect 24 items');
break;
}
} else {
t.is(dirItems.length, 4, 'expect 3 items (foo + subdir + subdir/bar + .snow)');
}
Expand Down

0 comments on commit 0deb12f

Please sign in to comment.