migrate tests to node:test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { describe, it, before, after } from 'node:test';
|
||||
/* jslint node:true */
|
||||
|
||||
import archives from '../archives.js';
|
||||
@@ -6,13 +7,9 @@ import backupSites from '../backupsites.js';
|
||||
import BoxError from '../boxerror.js';
|
||||
import common from './common.js';
|
||||
import constants from '../constants.js';
|
||||
import expect from 'expect.js';
|
||||
import assert from 'node:assert/strict';
|
||||
import safe from 'safetydance';
|
||||
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
describe('backups', function () {
|
||||
const { setup, cleanup, auditSource, getDefaultBackupSite } = common;
|
||||
@@ -60,28 +57,28 @@ describe('backups', function () {
|
||||
|
||||
it('can add another site', async function () {
|
||||
const id = await backupSites.add(backupSite, auditSource);
|
||||
expect(id).to.be.ok();
|
||||
assert.ok(id);
|
||||
backupSite.id = id;
|
||||
});
|
||||
|
||||
it('can list backup sites', async function () {
|
||||
const result = await backupSites.list();
|
||||
expect(result.length).to.be(2);
|
||||
assert.equal(result.length, 2);
|
||||
});
|
||||
|
||||
it('can get backup site', async function () {
|
||||
const result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.provider).to.be('filesystem');
|
||||
expect(result.config.backupDir).to.be.ok(); // the test sets this to some tmp location
|
||||
expect(result.format).to.be('tgz');
|
||||
expect(result.encryption).to.be(null);
|
||||
expect(result.contents).to.be(null);
|
||||
expect(result.enableForUpdates).to.be(true);
|
||||
assert.equal(result.provider, 'filesystem');
|
||||
assert.ok(result.config.backupDir); // the test sets this to some tmp location
|
||||
assert.equal(result.format, 'tgz');
|
||||
assert.equal(result.encryption, null);
|
||||
assert.equal(result.contents, null);
|
||||
assert.equal(result.enableForUpdates, true);
|
||||
});
|
||||
|
||||
it('cannot get random backup site', async function () {
|
||||
const result = await backupSites.get('random');
|
||||
expect(result).to.be(null);
|
||||
assert.equal(result, null);
|
||||
});
|
||||
|
||||
it('can set backup config', async function () {
|
||||
@@ -89,39 +86,39 @@ describe('backups', function () {
|
||||
await backupSites.setConfig(defaultBackupSite, newConfig, auditSource);
|
||||
|
||||
const result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.config.backupDir).to.be('/tmp/backups');
|
||||
assert.equal(result.config.backupDir, '/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);
|
||||
assert.equal(error.reason, 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 result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.schedule).to.be(pattern);
|
||||
assert.equal(result.schedule, 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);
|
||||
assert.equal(error.reason, 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 result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.retention).to.eql(retention);
|
||||
assert.deepEqual(result.retention, retention);
|
||||
}
|
||||
});
|
||||
|
||||
it('cannot disable for update', async function () {
|
||||
await backupSites.setEnabledForUpdates(defaultBackupSite, false, auditSource);
|
||||
const result = await backupSites.get(defaultBackupSite.id);
|
||||
expect(result.enableForUpdates).to.eql(false);
|
||||
assert.deepEqual(result.enableForUpdates, false);
|
||||
});
|
||||
|
||||
it('can delete all the backup sites', async function () {
|
||||
@@ -129,8 +126,8 @@ describe('backups', function () {
|
||||
backupSite.integrityKeyPair = {}; // keep removePrivateFields happy
|
||||
await backupSites.del(backupSite, auditSource);
|
||||
|
||||
expect(await backups.listByTypePaged(backups.BACKUP_TYPE_BOX, defaultBackupSite.id, 1, 10)).to.eql([]);
|
||||
expect(await archives.list(1, 10)).to.eql([]);
|
||||
expect(await backupSites.list()).to.eql([]);
|
||||
assert.deepEqual(await backups.listByTypePaged(backups.BACKUP_TYPE_BOX, defaultBackupSite.id, 1, 10), []);
|
||||
assert.deepEqual(await archives.list(1, 10), []);
|
||||
assert.deepEqual(await backupSites.list(), []);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user