2017-04-24 12:34:57 +02:00
|
|
|
/* jslint node:true */
|
|
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
2017-04-24 13:50:46 +02:00
|
|
|
appdb = require('../appdb.js'),
|
2017-04-24 12:34:57 +02:00
|
|
|
backupdb = require('../backupdb.js'),
|
|
|
|
|
backups = require('../backups.js'),
|
|
|
|
|
database = require('../database'),
|
|
|
|
|
DatabaseError = require('../databaseerror.js'),
|
|
|
|
|
expect = require('expect.js'),
|
|
|
|
|
settings = require('../settings.js');
|
|
|
|
|
|
2017-04-24 13:41:23 +02:00
|
|
|
describe('backups', function () {
|
2017-04-24 12:34:57 +02:00
|
|
|
before(function (done) {
|
|
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
|
|
|
|
database._clear,
|
|
|
|
|
settings.initialize,
|
|
|
|
|
settings.setBackupConfig.bind(null, {
|
|
|
|
|
provider: 'filesystem',
|
|
|
|
|
key: 'enckey',
|
|
|
|
|
retentionSecs: 1
|
|
|
|
|
})
|
|
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
|
async.series([
|
|
|
|
|
settings.uninitialize,
|
|
|
|
|
database._clear
|
|
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('cleanup', function () {
|
|
|
|
|
this.timeout(20000);
|
|
|
|
|
|
|
|
|
|
var BACKUP_0 = {
|
|
|
|
|
id: 'backup-box-0',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_BOX,
|
|
|
|
|
dependsOn: [ 'backup-app-00', 'backup-app-01' ],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var BACKUP_0_APP_0 = {
|
|
|
|
|
id: 'backup-app-00',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_APP,
|
|
|
|
|
dependsOn: [],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var BACKUP_0_APP_1 = {
|
|
|
|
|
id: 'backup-app-01',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_APP,
|
|
|
|
|
dependsOn: [],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var BACKUP_1 = {
|
|
|
|
|
id: 'backup-box-1',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_BOX,
|
|
|
|
|
dependsOn: [ 'backup-app-10', 'backup-app-11' ],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var BACKUP_1_APP_0 = {
|
|
|
|
|
id: 'backup-app-10',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_APP,
|
|
|
|
|
dependsOn: [],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var BACKUP_1_APP_1 = {
|
|
|
|
|
id: 'backup-app-11',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
type: backupdb.BACKUP_TYPE_APP,
|
|
|
|
|
dependsOn: [],
|
|
|
|
|
restoreConfig: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('succeeds without backups', function (done) {
|
|
|
|
|
backups.cleanup(done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds with box backups, keeps latest', function (done) {
|
|
|
|
|
async.eachSeries([[ BACKUP_0, BACKUP_0_APP_0, BACKUP_0_APP_1 ], [ BACKUP_1, BACKUP_1_APP_0, BACKUP_1_APP_1 ]], function (backup, callback) {
|
|
|
|
|
// space out backups
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
async.each(backup, backupdb.add, callback);
|
|
|
|
|
}, 2000);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backups.cleanup(function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backups.getPaged(1, 1000, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result.length).to.equal(1);
|
|
|
|
|
expect(result[0].id).to.equal(BACKUP_1.id);
|
|
|
|
|
|
|
|
|
|
// check that app backups are gone as well
|
|
|
|
|
backupdb.get(BACKUP_0_APP_0.id, function (error) {
|
|
|
|
|
expect(error).to.be.a(DatabaseError);
|
|
|
|
|
expect(error.reason).to.equal(DatabaseError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not remove expired backups if only one left', function (done) {
|
|
|
|
|
backups.cleanup(function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backups.getPaged(1, 1000, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result.length).to.equal(1);
|
|
|
|
|
expect(result[0].id).to.equal(BACKUP_1.id);
|
|
|
|
|
|
2017-04-24 13:41:23 +02:00
|
|
|
// check that app backups are also still there
|
|
|
|
|
backupdb.get(BACKUP_1_APP_0.id, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result.id).to.equal(BACKUP_1_APP_0.id);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-04-24 12:34:57 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-04-24 13:41:23 +02:00
|
|
|
|
|
|
|
|
it('succeeds for app backups not referenced by a box backup', function (done) {
|
|
|
|
|
async.eachSeries([BACKUP_0_APP_0, BACKUP_0_APP_1], backupdb.add, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
// wait for expiration
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
backups.cleanup(function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backupdb.getPaged(backupdb.BACKUP_TYPE_APP, 1, 1000, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result.length).to.equal(2);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}, 2000);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-04-24 13:50:46 +02:00
|
|
|
|
|
|
|
|
it('succeeds for app backups not referenced by a box backup or app', function (done) {
|
|
|
|
|
var APP_0 = {
|
|
|
|
|
id: 'appid-0',
|
|
|
|
|
appStoreId: 'appStoreId-0',
|
|
|
|
|
dnsRecordId: null,
|
|
|
|
|
installationState: appdb.ISTATE_PENDING_INSTALL,
|
|
|
|
|
installationProgress: null,
|
|
|
|
|
runState: null,
|
|
|
|
|
location: 'some-location-0',
|
|
|
|
|
manifest: { version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0' },
|
|
|
|
|
httpPort: null,
|
|
|
|
|
containerId: null,
|
|
|
|
|
portBindings: { port: 5678 },
|
|
|
|
|
health: null,
|
|
|
|
|
accessRestriction: null,
|
|
|
|
|
lastBackupId: null,
|
|
|
|
|
oldConfig: null,
|
|
|
|
|
memoryLimit: 4294967296,
|
|
|
|
|
altDomain: null,
|
|
|
|
|
xFrameOptions: 'DENY',
|
|
|
|
|
sso: true,
|
|
|
|
|
debugMode: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async.eachSeries([BACKUP_0_APP_0, BACKUP_0_APP_1], backupdb.add, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
// wait for expiration
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
// now reference one backup
|
|
|
|
|
APP_0.lastBackupId = BACKUP_0_APP_0.id;
|
|
|
|
|
|
|
|
|
|
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.portBindings, APP_0, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backups.cleanup(function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
backupdb.getPaged(backupdb.BACKUP_TYPE_APP, 1, 1000, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result.length).to.equal(3);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}, 2000);
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-04-24 12:34:57 +02:00
|
|
|
});
|
|
|
|
|
});
|