tasks -> changes

This commit is contained in:
Girish Ramakrishnan
2025-02-13 17:08:39 +01:00
parent 326e01d548
commit 221181092e
+42 -42
View File
@@ -23,7 +23,7 @@ describe('Syncer', function () {
console.log('Tests are run in %s with cache file %s', gTmpDir, gCacheFile);
});
async function getTasks(dataLayout) {
async function getChanges(dataLayout) {
const changes = await syncer.sync(dataLayout);
syncer.finalize(changes);
return changes.delQueue.concat(changes.addQueue);
@@ -34,8 +34,8 @@ describe('Syncer', function () {
createTree(gTmpDir, { });
const dataLayout = new DataLayout(gTmpDir, []);
const tasks = await getTasks(dataLayout);
expect(tasks).to.eql([{ operation: 'removedir', path: '', reason: 'nocache' }]);
const changes = await getChanges(dataLayout);
expect(changes).to.eql([{ operation: 'removedir', path: '', reason: 'nocache' }]);
});
it('empty cache - adds all', async function () {
@@ -43,9 +43,9 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
const tasks = await getTasks(dataLayout);
const changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'add', path: 'src/index.js', reason: 'new', position: 0 },
{ operation: 'add', path: 'test/test.js', reason: 'new', position: 1 },
{ operation: 'add', path: 'walrus', reason: 'new', position: 2 }
@@ -57,9 +57,9 @@ describe('Syncer', function () {
createTree(gTmpDir, { a: { b: { c: { d: { e: 'some code' } } } } });
const dataLayout = new DataLayout(gTmpDir, []);
const tasks = await getTasks(dataLayout);
const changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'add', path: 'a/b/c/d/e', reason: 'new', position: 0 }
]);
});
@@ -69,9 +69,9 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'link:file': '/tmp', 'readme': 'this is readme' });
const dataLayout = new DataLayout(gTmpDir, []);
const tasks = await getTasks(dataLayout);
const changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'add', path: 'readme', reason: 'new', position: 0 }
]);
});
@@ -81,15 +81,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(3);
expect(changes.length).to.be(3);
execSync('touch src/index.js test/test.js', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'add', path: 'src/index.js', reason: 'changed', position: 0 },
{ operation: 'add', path: 'test/test.js', reason: 'changed', position: 1 }
]);
@@ -100,15 +100,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(3);
expect(changes.length).to.be(3);
execSync('rm src/index.js walrus', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'remove', path: 'src/index.js', reason: 'missing' },
{ operation: 'remove', path: 'walrus', reason: 'missing' }
]);
@@ -119,15 +119,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(3);
expect(changes.length).to.be(3);
execSync('rm -rf src test', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'removedir', path: 'src', reason: 'missing' },
{ operation: 'removedir', path: 'test', reason: 'missing' }
]);
@@ -138,15 +138,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(3);
expect(changes.length).to.be(3);
execSync('find . -delete', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'removedir', path: 'src', reason: 'missing' },
{ operation: 'removedir', path: 'test', reason: 'missing' },
{ operation: 'remove', path: 'walrus', reason: 'missing' }
@@ -158,15 +158,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { a: { b: { c: { d: { e: 'some code' } } } } });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(1);
expect(changes.length).to.be(1);
execSync('rm -r a/b; touch a/f', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'removedir', path: 'a/b', reason: 'missing' },
{ operation: 'add', path: 'a/f', reason: 'new', position: 0 }
]);
@@ -177,15 +177,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'data': { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'This is a README' }, 'walrus': 'animal' } });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(3);
expect(changes.length).to.be(3);
execSync('rm data/test/test.js; mkdir data/test/test.js; touch data/test/test.js/trick', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'remove', path: 'data/test/test.js', reason: 'wasfile' },
{ operation: 'add', path: 'data/test/test.js/trick', reason: 'new', position: 0 }
]);
@@ -196,15 +196,15 @@ describe('Syncer', function () {
createTree(gTmpDir, { 'src': { 'index.js': 'some code' }, 'test': { 'test.js': 'this', 'test2.js': 'test' }, 'walrus': 'animal' });
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
expect(tasks.length).to.be(4);
expect(changes.length).to.be(4);
execSync('rm -r test; touch test', { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'removedir', path: 'test', reason: 'wasdir' },
{ operation: 'add', path: 'test', reason: 'wasdir', position: 0 }
]);
@@ -229,7 +229,7 @@ describe('Syncer', function () {
});
const dataLayout = new DataLayout(gTmpDir, []);
let tasks = await getTasks(dataLayout);
let changes = await getChanges(dataLayout);
execSync(`rm a; \
mkdir a; \
@@ -242,9 +242,9 @@ describe('Syncer', function () {
touch j/k/file; \
rmdir j/m;`, { cwd: gTmpDir });
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks).to.eql([
expect(changes).to.eql([
{ operation: 'remove', path: 'a', reason: 'wasfile' },
{ operation: 'remove', path: 'a2', reason: 'missing' },
{ operation: 'remove', path: 'file', reason: 'missing' },
@@ -257,8 +257,8 @@ describe('Syncer', function () {
{ operation: 'add', path: 'j/k/file', reason: 'new', position: 2 },
]);
tasks = await getTasks(dataLayout);
changes = await getChanges(dataLayout);
expect(tasks.length).to.be(0);
expect(changes.length).to.be(0);
});
});