settings: move backup settings
This commit is contained in:
@@ -216,7 +216,7 @@ describe('backup cleaner', function () {
|
||||
backupFolder: '/tmp/someplace',
|
||||
format: 'tgz'
|
||||
}));
|
||||
await settings.setBackupPolicy({ retention: { keepWithinSecs: 1 }, schedule: '00 00 23 * * *' });
|
||||
await backups.setPolicy({ retention: { keepWithinSecs: 1 }, schedule: '00 00 23 * * *' });
|
||||
});
|
||||
|
||||
async function cleanupBackups() {
|
||||
|
||||
@@ -48,66 +48,104 @@ describe('backups', function () {
|
||||
label: ''
|
||||
};
|
||||
|
||||
it('add succeeds', async function () {
|
||||
boxBackup.id = await backups.add(boxBackup);
|
||||
describe('crud', function () {
|
||||
it('add succeeds', async function () {
|
||||
boxBackup.id = await backups.add(boxBackup);
|
||||
});
|
||||
|
||||
it('fails with duplicate path', async function () {
|
||||
const [error] = await safe(backups.add(boxBackup));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
|
||||
it('get succeeds', async function () {
|
||||
const result = await backups.get(boxBackup.id);
|
||||
delete result.creationTime;
|
||||
expect(result).to.eql(boxBackup);
|
||||
});
|
||||
|
||||
it('get of unknown id fails', async function () {
|
||||
const result = await backups.get('somerandom');
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('getByTypePaged succeeds', async function () {
|
||||
const results = await backups.getByTypePaged(backups.BACKUP_TYPE_BOX, 1, 5);
|
||||
expect(results.length).to.be(1);
|
||||
delete results[0].creationTime;
|
||||
expect(results[0]).to.eql(boxBackup);
|
||||
});
|
||||
|
||||
it('update succeeds', async function () {
|
||||
await backups.update(boxBackup.id, { label: 'DuMonde', preserveSecs: 30 });
|
||||
const result = await backups.get(boxBackup.id);
|
||||
expect(result.label).to.eql('DuMonde');
|
||||
expect(result.preserveSecs).to.eql(30);
|
||||
});
|
||||
|
||||
it('delete succeeds', async function () {
|
||||
await backups.del(boxBackup.id);
|
||||
const result = await backups.get(boxBackup.id);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('add app backup succeeds', async function () {
|
||||
appBackup.id = await backups.add(appBackup);
|
||||
});
|
||||
|
||||
it('get app backup succeeds', async function () {
|
||||
const result = await backups.get(appBackup.id);
|
||||
delete result.creationTime;
|
||||
expect(result).to.eql(appBackup);
|
||||
});
|
||||
|
||||
it('getByIdentifierAndStatePaged succeeds', async function () {
|
||||
const results = await backups.getByIdentifierAndStatePaged(appBackup.identifier, backups.BACKUP_STATE_CREATING, 1, 5);
|
||||
expect(results.length).to.be(1);
|
||||
delete results[0].creationTime;
|
||||
expect(results[0]).to.eql(appBackup);
|
||||
});
|
||||
|
||||
it('delete app backup succeeds', async function () {
|
||||
await backups.del(appBackup.id);
|
||||
const result = await backups.get(appBackup.id);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails with duplicate path', async function () {
|
||||
const [error] = await safe(backups.add(boxBackup));
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
});
|
||||
describe('config and policy', function () {
|
||||
it('can get backup config', async function () {
|
||||
const backupConfig = await backups.getConfig();
|
||||
expect(backupConfig.provider).to.be('filesystem');
|
||||
expect(backupConfig.backupFolder).to.be('/var/backups');
|
||||
});
|
||||
|
||||
it('get succeeds', async function () {
|
||||
const result = await backups.get(boxBackup.id);
|
||||
delete result.creationTime;
|
||||
expect(result).to.eql(boxBackup);
|
||||
});
|
||||
it('can set backup config', async function () {
|
||||
let backupConfig = await backups.getConfig();
|
||||
backupConfig = Object.assign({}, backupConfig, { backupFolder: '/tmp/backups' });
|
||||
await backups.setConfig(backupConfig);
|
||||
|
||||
it('get of unknown id fails', async function () {
|
||||
const result = await backups.get('somerandom');
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
const newBackupConfig = await backups.getConfig();
|
||||
expect(newBackupConfig.backupFolder).to.be('/tmp/backups');
|
||||
});
|
||||
|
||||
it('getByTypePaged succeeds', async function () {
|
||||
const results = await backups.getByTypePaged(backups.BACKUP_TYPE_BOX, 1, 5);
|
||||
expect(results.length).to.be(1);
|
||||
delete results[0].creationTime;
|
||||
expect(results[0]).to.eql(boxBackup);
|
||||
});
|
||||
it('cannot set backup policy with invalid schedule', async function () {
|
||||
const [error] = await safe(backups.setPolicy({ schedule: '', retention: { keepWithinSecs: 1 }}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('update succeeds', async function () {
|
||||
await backups.update(boxBackup.id, { label: 'DuMonde', preserveSecs: 30 });
|
||||
const result = await backups.get(boxBackup.id);
|
||||
expect(result.label).to.eql('DuMonde');
|
||||
expect(result.preserveSecs).to.eql(30);
|
||||
});
|
||||
it('cannot set backup policy with missing retention', async function () {
|
||||
const [error] = await safe(backups.setPolicy({ schedule: '00 * * * * *'}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('delete succeeds', async function () {
|
||||
await backups.del(boxBackup.id);
|
||||
const result = await backups.get(boxBackup.id);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
it('cannot set backup policy with invalid retention', async function () {
|
||||
const [error] = await safe(backups.setPolicy({ schedule: '00 * * * * *', retention: { keepWhenever: 4 }}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('add app backup succeeds', async function () {
|
||||
appBackup.id = await backups.add(appBackup);
|
||||
});
|
||||
|
||||
it('get app backup succeeds', async function () {
|
||||
const result = await backups.get(appBackup.id);
|
||||
delete result.creationTime;
|
||||
expect(result).to.eql(appBackup);
|
||||
});
|
||||
|
||||
it('getByIdentifierAndStatePaged succeeds', async function () {
|
||||
const results = await backups.getByIdentifierAndStatePaged(appBackup.identifier, backups.BACKUP_STATE_CREATING, 1, 5);
|
||||
expect(results.length).to.be(1);
|
||||
delete results[0].creationTime;
|
||||
expect(results[0]).to.eql(appBackup);
|
||||
});
|
||||
|
||||
it('delete app backup succeeds', async function () {
|
||||
await backups.del(appBackup.id);
|
||||
const result = await backups.get(appBackup.id);
|
||||
expect(result).to.be(null);
|
||||
it('can set valid backup policy', async function () {
|
||||
await backups.setPolicy({ schedule: '00 00 2,23 * * 0,1,2', retention: { keepWithinSecs: 1 }});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ const backups = require('../backups.js'),
|
||||
fs = require('fs'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
settings = require('../settings.js'),
|
||||
tasks = require('../tasks.js'),
|
||||
timers = require('timers/promises');
|
||||
|
||||
@@ -34,7 +33,7 @@ describe('backuptask', function () {
|
||||
before(async function () {
|
||||
fs.rmSync(backupConfig.backupFolder, { recursive: true, force: true });
|
||||
|
||||
await settings.setBackupConfig(backupConfig);
|
||||
await backups.setConfig(backupConfig);
|
||||
});
|
||||
|
||||
async function createBackup() {
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('./common.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
expect = require('expect.js'),
|
||||
settings = require('../settings.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('Settings', function () {
|
||||
const { setup, cleanup } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('can get backup config', async function () {
|
||||
const backupConfig = await settings.getBackupConfig();
|
||||
expect(backupConfig.provider).to.be('filesystem');
|
||||
expect(backupConfig.backupFolder).to.be('/var/backups');
|
||||
});
|
||||
|
||||
it('can set backup config', async function () {
|
||||
let backupConfig = await settings.getBackupConfig();
|
||||
backupConfig = Object.assign({}, backupConfig, { backupFolder: '/tmp/backups' });
|
||||
await settings.setBackupConfig(backupConfig);
|
||||
|
||||
const newBackupConfig = await settings.getBackupConfig();
|
||||
expect(newBackupConfig.backupFolder).to.be('/tmp/backups');
|
||||
});
|
||||
|
||||
it('cannot set backup policy with invalid schedule', async function () {
|
||||
const [error] = await safe(settings.setBackupPolicy({ schedule: '', retention: { keepWithinSecs: 1 }}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('cannot set backup policy with missing retention', async function () {
|
||||
const [error] = await safe(settings.setBackupPolicy({ schedule: '00 * * * * *'}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('cannot set backup policy with invalid retention', async function () {
|
||||
const [error] = await safe(settings.setBackupPolicy({ schedule: '00 * * * * *', retention: { keepWhenever: 4 }}));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can set valid backup policy', async function () {
|
||||
await settings.setBackupPolicy({ schedule: '00 00 2,23 * * 0,1,2', retention: { keepWithinSecs: 1 }});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const BoxError = require('../boxerror.js'),
|
||||
const backups = require('../backups.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
execSync = require('child_process').execSync,
|
||||
expect = require('expect.js'),
|
||||
@@ -19,8 +20,7 @@ const BoxError = require('../boxerror.js'),
|
||||
path = require('path'),
|
||||
readdirp = require('readdirp'),
|
||||
s3 = require('../storage/s3.js'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js');
|
||||
safe = require('safetydance');
|
||||
|
||||
const chunk = s3._chunk;
|
||||
|
||||
@@ -55,12 +55,12 @@ describe('Storage', function () {
|
||||
|
||||
it('fails to set backup config for bad folder', async function () {
|
||||
const tmp = Object.assign({}, gBackupConfig, { backupFolder: '/root/oof' });
|
||||
const [error] = await safe(settings.setBackupConfig(tmp));
|
||||
const [error] = await safe(backups.setConfig(tmp));
|
||||
expect(error.reason).to.equal(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('succeeds to set backup config', async function () {
|
||||
await settings.setBackupConfig(gBackupConfig);
|
||||
await backups.setConfig(gBackupConfig);
|
||||
expect(fs.existsSync(path.join(gBackupConfig.backupFolder, 'snapshot'))).to.be(true); // auto-created
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user