rename backupTargets to backupSites
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
/* jslint node:true */
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const archives = require('../archives.js'),
|
||||
backups = require('../backups.js'),
|
||||
backupSites = require('../backupsites.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('backups', function () {
|
||||
const { setup, cleanup, auditSource, getDefaultBackupSite } = common;
|
||||
|
||||
before(async function () {
|
||||
await setup();
|
||||
});
|
||||
after(cleanup);
|
||||
|
||||
const backupSite = {
|
||||
provider: 'filesystem',
|
||||
name: 'Another',
|
||||
config: { backupDir: '/tmp/boxtest2' },
|
||||
format: 'rsync',
|
||||
retention: { keepWithinSecs: 2 * 24 * 60 * 60 },
|
||||
schedule: '00 00 23 * * *'
|
||||
};
|
||||
|
||||
const appBackup = {
|
||||
id: null,
|
||||
remotePath: 'backup-box',
|
||||
encryptionVersion: 2,
|
||||
packageVersion: '1.0.0',
|
||||
type: backups.BACKUP_TYPE_APP,
|
||||
state: backups.BACKUP_STATE_NORMAL,
|
||||
identifier: 'box',
|
||||
dependsOn: [ 'dep1' ],
|
||||
manifest: null,
|
||||
preserveSecs: 0,
|
||||
label: '',
|
||||
appConfig: { loc: 'loc1' },
|
||||
siteId: null
|
||||
};
|
||||
|
||||
let defaultBackupSite = null;
|
||||
|
||||
before(async function () {
|
||||
appBackup.siteId = (await getDefaultBackupSite()).id;
|
||||
appBackup.id = await backups.add(appBackup);
|
||||
await archives.add(appBackup.id, {}, auditSource);
|
||||
});
|
||||
|
||||
it('can add another site', async function () {
|
||||
const id = await backupSites.add(backupSite, auditSource);
|
||||
expect(id).to.be.ok();
|
||||
backupSite.id = id;
|
||||
});
|
||||
|
||||
it('can list backup sites', async function () {
|
||||
const result = await backupSites.list(1, 5);
|
||||
expect(result.length).to.be(2);
|
||||
defaultBackupSite = result[0]; // first is always primary
|
||||
});
|
||||
|
||||
it('can get backup site', async function () {
|
||||
const backupSite = await backupSites.get(defaultBackupSite.id);
|
||||
expect(backupSite.provider).to.be('filesystem');
|
||||
expect(backupSite.config.backupDir).to.be.ok(); // the test sets this to some tmp location
|
||||
expect(backupSite.format).to.be('tgz');
|
||||
expect(backupSite.encryption).to.be(null);
|
||||
expect(backupSite.primary).to.be(true);
|
||||
});
|
||||
|
||||
it('cannot get random backup site', async function () {
|
||||
const backupSite = await backupSites.get('random');
|
||||
expect(backupSite).to.be(null);
|
||||
});
|
||||
|
||||
it('can set backup config', async function () {
|
||||
const newConfig = Object.assign({}, defaultBackupSite.config, { backupDir: '/tmp/backups' });
|
||||
await backupSites.setConfig(defaultBackupSite, newConfig, auditSource);
|
||||
|
||||
const result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.config.backupDir).to.be('/tmp/backups');
|
||||
});
|
||||
|
||||
it('cannot set invalid schedule', async function () {
|
||||
const [error] = await safe(backupSites.setSchedule(defaultBackupSite, '', auditSource));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can set valid schedule', async function () {
|
||||
for (const pattern of [ '00 * * * * *', constants.CRON_PATTERN_NEVER ]) {
|
||||
await backupSites.setSchedule(defaultBackupSite, pattern, auditSource);
|
||||
const backupSite = await backupSites.get(defaultBackupSite.id);
|
||||
expect(backupSite.schedule).to.be(pattern);
|
||||
}
|
||||
});
|
||||
|
||||
it('cannot set invalid retention', async function () {
|
||||
const [error] = await safe(backupSites.setRetention(defaultBackupSite, { keepWhenever: 4 }, auditSource));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can set valid retention', async function () {
|
||||
for (const retention of [ { keepWithinSecs: 1 }, { keepYearly: 3 }, { keepMonthly: 14 } ]) {
|
||||
await backupSites.setRetention(defaultBackupSite, retention, auditSource);
|
||||
const backupSite = await backupSites.get(defaultBackupSite.id);
|
||||
expect(backupSite.retention).to.eql(retention);
|
||||
}
|
||||
});
|
||||
|
||||
it('cannot delete the primary backup site', async function () {
|
||||
const [error] = await safe(backupSites.del(defaultBackupSite, auditSource));
|
||||
expect(error.reason).to.be(BoxError.CONFLICT);
|
||||
});
|
||||
|
||||
it('can set another as primary', async function () {
|
||||
await backupSites.setPrimary(backupSite, auditSource);
|
||||
|
||||
const noMoreDefaultSite = await backupSites.get(defaultBackupSite.id);
|
||||
expect(noMoreDefaultSite.primary).to.be(false);
|
||||
defaultBackupSite.primary = false;
|
||||
});
|
||||
|
||||
it('can delete non-primary backup site', async function () {
|
||||
await backupSites.del(defaultBackupSite, auditSource);
|
||||
expect(await backups.list(1, 10)).to.eql([]);
|
||||
expect(await archives.list(1, 10)).to.eql([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user