backups: split config and policy
keeping them together makes the test/validation quite complicated. for example, when policy is changed, we test the storage backends part of #817
This commit is contained in:
@@ -23,8 +23,6 @@ describe('Backups API', function () {
|
||||
backupFolder: '/tmp/backups',
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
retentionPolicy: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
schedulePattern: '00 00 23 * * *' // every day at 11pm
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -169,6 +169,97 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_policy', function () {
|
||||
const defaultPolicy = {
|
||||
retention: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
schedule: '00 00 23 * * *' // every day at 11pm
|
||||
};
|
||||
|
||||
it('cannot set backup_policy without schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.schedule;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid schedule', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.schedule = 'not a pattern';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy without retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
delete tmp.retention;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with invalid retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = 'not an object';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with empty retention', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = {};
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention missing properties', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { foo: 'bar' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_policy with retention with invalid keepWithinSecs', async function () {
|
||||
const tmp = Object.assign({} , defaultPolicy);
|
||||
tmp.retention = { keepWithinSecs: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_policy`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup_config', function () {
|
||||
// keep in sync with defaults in settings.js
|
||||
let defaultConfig = {
|
||||
@@ -176,8 +267,6 @@ describe('Settings API', function () {
|
||||
backupFolder: '/var/backups',
|
||||
format: 'tgz',
|
||||
encryption: null,
|
||||
retentionPolicy: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
||||
schedulePattern: '00 00 23 * * *' // every day at 11pm
|
||||
};
|
||||
|
||||
it('can get backup_config (default)', async function () {
|
||||
@@ -212,30 +301,6 @@ describe('Settings API', function () {
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without schedulePattern', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.schedulePattern;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid schedulePattern', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.schedulePattern = 'not a pattern';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without format', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.format;
|
||||
@@ -260,66 +325,6 @@ describe('Settings API', function () {
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config without retentionPolicy', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
delete tmp.retentionPolicy;
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid retentionPolicy', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = 'not an object';
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with empty retentionPolicy', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = {};
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with retentionPolicy missing properties', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = { foo: 'bar' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with retentionPolicy with invalid keepWithinSecs', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.retentionPolicy = { keepWithinSecs: 'not a number' };
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/settings/backup_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send(tmp)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot set backup_config with invalid password', async function () {
|
||||
let tmp = JSON.parse(JSON.stringify(defaultConfig));
|
||||
tmp.password = 1234;
|
||||
|
||||
Reference in New Issue
Block a user