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:
@@ -35,28 +35,28 @@ describe('backup cleaner', function () {
|
||||
preserveSecs: 0
|
||||
};
|
||||
|
||||
describe('retention policy', function () {
|
||||
describe('retention', function () {
|
||||
it('keeps latest', function () {
|
||||
const backup = Object.assign({}, backupTemplate, { creationTime: moment().subtract(5, 's').toDate(), state: backups.BACKUP_STATE_NORMAL });
|
||||
backupCleaner._applyBackupRetentionPolicy([backup], { keepWithinSecs: 1, keepLatest: true }, []);
|
||||
backupCleaner._applyBackupRetention([backup], { keepWithinSecs: 1, keepLatest: true }, []);
|
||||
expect(backup.keepReason).to.be('latest');
|
||||
});
|
||||
|
||||
it('does not keep latest', function () {
|
||||
let backup = { creationTime: moment().subtract(5, 's').toDate(), state: backups.BACKUP_STATE_NORMAL };
|
||||
backupCleaner._applyBackupRetentionPolicy([backup], { keepWithinSecs: 1, keepLatest: false }, []);
|
||||
backupCleaner._applyBackupRetention([backup], { keepWithinSecs: 1, keepLatest: false }, []);
|
||||
expect(backup.keepReason).to.be(undefined);
|
||||
});
|
||||
|
||||
it('always keeps forever policy', function () {
|
||||
let backup = { creationTime: new Date() };
|
||||
backupCleaner._applyBackupRetentionPolicy([backup], { keepWithinSecs: -1, keepLatest: true }, []);
|
||||
backupCleaner._applyBackupRetention([backup], { keepWithinSecs: -1, keepLatest: true }, []);
|
||||
expect(backup.keepReason).to.be('keepWithinSecs');
|
||||
});
|
||||
|
||||
it('preserveSecs takes precedence', function () {
|
||||
let backup = { creationTime: new Date(), preserveSecs: 3000 };
|
||||
backupCleaner._applyBackupRetentionPolicy([backup], { keepWithinSecs: 1, keepLatest: true }, []);
|
||||
backupCleaner._applyBackupRetention([backup], { keepWithinSecs: 1, keepLatest: true }, []);
|
||||
expect(backup.keepReason).to.be('preserveSecs');
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('backup cleaner', function () {
|
||||
{ id: '3', state: backups.BACKUP_STATE_NORMAL, creationTime: moment().subtract(20, 'h').toDate() },
|
||||
{ id: '4', state: backups.BACKUP_STATE_NORMAL, creationTime: moment().subtract(5, 'd').toDate() }
|
||||
];
|
||||
backupCleaner._applyBackupRetentionPolicy(b, { keepDaily: 1, keepLatest: true }, []);
|
||||
backupCleaner._applyBackupRetention(b, { keepDaily: 1, keepLatest: true }, []);
|
||||
expect(b[0].keepReason).to.be('keepDaily');
|
||||
expect(b[1].keepReason).to.be(undefined);
|
||||
expect(b[2].keepReason).to.be(undefined);
|
||||
@@ -87,7 +87,7 @@ describe('backup cleaner', function () {
|
||||
{ id: '5', state: backups.BACKUP_STATE_CREATING, creationTime: moment().subtract(50, 'h').toDate() },
|
||||
{ id: '6', state: backups.BACKUP_STATE_NORMAL, creationTime: moment().subtract(5, 'd').toDate() }
|
||||
];
|
||||
backupCleaner._applyBackupRetentionPolicy(b, { keepDaily: 2, keepWeekly: 1, keepLatest: false }, []);
|
||||
backupCleaner._applyBackupRetention(b, { keepDaily: 2, keepWeekly: 1, keepLatest: false }, []);
|
||||
expect(b[0].keepReason).to.be('keepDaily'); // today
|
||||
expect(b[1].keepReason).to.be('keepWeekly'); // today
|
||||
expect(b[2].keepReason).to.be(undefined);
|
||||
@@ -110,7 +110,7 @@ describe('backup cleaner', function () {
|
||||
{ id: '8', state: backups.BACKUP_STATE_NORMAL, creationTime: moment().subtract(84, 'd').toDate() },
|
||||
{ id: '9', state: backups.BACKUP_STATE_NORMAL, creationTime: moment().subtract(97, 'd').toDate() },
|
||||
];
|
||||
backupCleaner._applyBackupRetentionPolicy(b, { keepDaily: 2, keepMonthly: 3, keepYearly: 1, keepLatest: true }, []);
|
||||
backupCleaner._applyBackupRetention(b, { keepDaily: 2, keepMonthly: 3, keepYearly: 1, keepLatest: true }, []);
|
||||
expect(b[0].keepReason).to.be('creating');
|
||||
expect(b[1].discardReason).to.be('error'); // errored
|
||||
expect(b[2].keepReason).to.be('keepDaily');
|
||||
@@ -214,9 +214,9 @@ describe('backup cleaner', function () {
|
||||
provider: 'filesystem',
|
||||
password: 'supersecret',
|
||||
backupFolder: '/tmp/someplace',
|
||||
retentionPolicy: { keepWithinSecs: 1 },
|
||||
format: 'tgz'
|
||||
}));
|
||||
await settings.setBackupPolicy({ retention: { keepWithinSecs: 1 }, schedule: '00 00 23 * * *' });
|
||||
});
|
||||
|
||||
async function cleanupBackups() {
|
||||
|
||||
Reference in New Issue
Block a user