backuptargets: fix del to delete archives as well

This commit is contained in:
Girish Ramakrishnan
2025-08-04 10:16:19 +02:00
parent 5c1147bfa4
commit 2c80c4a7d5
2 changed files with 38 additions and 4 deletions
+35 -2
View File
@@ -21,12 +21,27 @@ describe('backups', function () {
});
after(cleanup);
const backupTarget = {
provider: 'filesystem',
label: 'Another',
config: { backupDir: '/tmp/boxtest2' },
format: 'rsync',
retention: { keepWithinSecs: 2 * 24 * 60 * 60 },
schedule: '00 00 23 * * *'
};
let defaultBackupTarget = null;
it('can add another target', async function () {
const id = await backupTargets.add(backupTarget, auditSource);
expect(id).to.be.ok();
backupTarget.id = id;
});
it('can list backup targets', async function () {
const result = await backupTargets.list(1, 5);
expect(result.length).to.be(1);
defaultBackupTarget = result[0];
expect(result.length).to.be(2);
defaultBackupTarget = result[0]; // first is always primary
});
it('can get backup target', async function () {
@@ -35,6 +50,7 @@ describe('backups', function () {
expect(backupTarget.config.backupDir).to.be.ok(); // the test sets this to some tmp location
expect(backupTarget.format).to.be('tgz');
expect(backupTarget.encryption).to.be(null);
expect(backupTarget.primary).to.be(true);
});
it('cannot get random backup target', async function () {
@@ -75,4 +91,21 @@ describe('backups', function () {
expect(backupTarget.retention).to.eql(retention);
}
});
it('cannot delete the primary backup target', async function () {
const [error] = await safe(backupTargets.del(defaultBackupTarget, auditSource));
expect(error.reason).to.be(BoxError.CONFLICT);
});
it('can set another as primary', async function () {
await backupTargets.setPrimary(backupTarget, auditSource);
const noMoreDefaultTarget = await backupTargets.get(defaultBackupTarget.id);
expect(noMoreDefaultTarget.primary).to.be(false);
defaultBackupTarget.primary = false;
});
it('can delete non-primary backup target', async function () {
await backupTargets.del(defaultBackupTarget, auditSource);
});
});