filesystem: rename backupFolder to backupDir
This commit is contained in:
@@ -33,7 +33,7 @@ describe('Storage', function () {
|
||||
|
||||
const gBackupConfig = {
|
||||
key: 'key',
|
||||
backupFolder: null,
|
||||
backupDir: null,
|
||||
prefix: 'someprefix'
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Storage', function () {
|
||||
before(async function () {
|
||||
gTmpFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'filesystem-storage-test_'));
|
||||
defaultBackupTarget = await getDefaultBackupTarget();
|
||||
gBackupConfig.backupFolder = path.join(gTmpFolder, 'backups/');
|
||||
gBackupConfig.backupDir = path.join(gTmpFolder, 'backups/');
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
@@ -51,20 +51,20 @@ describe('Storage', function () {
|
||||
});
|
||||
|
||||
it('fails to set backup storage for bad folder', async function () {
|
||||
const tmp = Object.assign({}, gBackupConfig, { backupFolder: '/root/oof' });
|
||||
const tmp = Object.assign({}, gBackupConfig, { backupDir: '/root/oof' });
|
||||
const [error] = await safe(backupTargets.setConfig(defaultBackupTarget, tmp, auditSource));
|
||||
expect(error.reason).to.equal(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('succeeds to set backup storage', async function () {
|
||||
await backupTargets.setConfig(defaultBackupTarget, gBackupConfig, auditSource);
|
||||
expect(fs.existsSync(path.join(gBackupConfig.backupFolder, 'someprefix/snapshot'))).to.be(true); // auto-created
|
||||
expect(fs.existsSync(path.join(gBackupConfig.backupDir, 'someprefix/snapshot'))).to.be(true); // auto-created
|
||||
});
|
||||
|
||||
it('can upload', async function () {
|
||||
const sourceFile = path.join(__dirname, 'storage/data/test.txt');
|
||||
const sourceStream = fs.createReadStream(sourceFile);
|
||||
const destFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const destFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const uploader = await filesystem.upload(gBackupConfig, 'uploadtest/test.txt');
|
||||
await stream.pipeline(sourceStream, uploader.stream);
|
||||
await uploader.finish();
|
||||
@@ -75,7 +75,7 @@ describe('Storage', function () {
|
||||
xit('upload waits for empty file to be created', async function () {
|
||||
const sourceFile = path.join(__dirname, 'storage/data/empty');
|
||||
const sourceStream = fs.createReadStream(sourceFile);
|
||||
const destFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/empty');
|
||||
const destFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/empty');
|
||||
const uploader = await filesystem.upload(gBackupConfig, destFile);
|
||||
await stream.pipeline(sourceStream, uploader.stream);
|
||||
await uploader.finish();
|
||||
@@ -86,7 +86,7 @@ describe('Storage', function () {
|
||||
it('upload unlinks old file', async function () {
|
||||
const sourceFile = path.join(__dirname, 'storage/data/test.txt');
|
||||
const sourceStream = fs.createReadStream(sourceFile);
|
||||
const destFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const destFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const oldStat = fs.statSync(destFile);
|
||||
const uploader = await filesystem.upload(gBackupConfig, 'uploadtest/test.txt');
|
||||
await stream.pipeline(sourceStream, uploader.stream);
|
||||
@@ -97,7 +97,7 @@ describe('Storage', function () {
|
||||
});
|
||||
|
||||
it('can download file', async function () {
|
||||
const sourceFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const sourceFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test.txt');
|
||||
const [error, stream] = await safe(filesystem.download(gBackupConfig, 'uploadtest/test.txt'));
|
||||
expect(error).to.be(null);
|
||||
expect(stream).to.be.an('object');
|
||||
@@ -112,7 +112,7 @@ describe('Storage', function () {
|
||||
|
||||
it('list dir lists the source dir', async function () {
|
||||
const sourceDir = path.join(__dirname, 'storage');
|
||||
execSync(`cp -r ${sourceDir} ${gBackupConfig.backupFolder}/${gBackupConfig.prefix}`, { encoding: 'utf8' });
|
||||
execSync(`cp -r ${sourceDir} ${gBackupConfig.backupDir}/${gBackupConfig.prefix}`, { encoding: 'utf8' });
|
||||
|
||||
let allFiles = [], marker = null;
|
||||
while (true) {
|
||||
@@ -127,22 +127,22 @@ describe('Storage', function () {
|
||||
});
|
||||
|
||||
it('can copy', async function () {
|
||||
// const sourceFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test.txt'); // keep the test within same device
|
||||
const destFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test-hardlink.txt');
|
||||
// const sourceFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test.txt'); // keep the test within same device
|
||||
const destFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test-hardlink.txt');
|
||||
|
||||
await filesystem.copy(gBackupConfig, 'uploadtest/test.txt', 'uploadtest/test-hardlink.txt', () => {});
|
||||
expect(fs.statSync(destFile).nlink).to.be(2); // created a hardlink
|
||||
});
|
||||
|
||||
it('can remove file', async function () {
|
||||
const sourceFile = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, '/uploadtest/test-hardlink.txt');
|
||||
const sourceFile = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, '/uploadtest/test-hardlink.txt');
|
||||
|
||||
await filesystem.remove(gBackupConfig, 'uploadtest/test-hardlink.txt');
|
||||
expect(fs.existsSync(sourceFile)).to.be(false);
|
||||
});
|
||||
|
||||
it('can remove empty dir', async function () {
|
||||
const sourceDir = path.join(gBackupConfig.backupFolder, gBackupConfig.prefix, 'emptydir');
|
||||
const sourceDir = path.join(gBackupConfig.backupDir, gBackupConfig.prefix, 'emptydir');
|
||||
fs.mkdirSync(sourceDir);
|
||||
|
||||
await filesystem.remove(gBackupConfig, 'emptydir', () => {});
|
||||
|
||||
Reference in New Issue
Block a user