fix storage test
This commit is contained in:
@@ -46,8 +46,8 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
describe('digitalocean', function () {
|
||||
let TOKEN = 'sometoken';
|
||||
let DIGITALOCEAN_ENDPOINT = 'https://api.digitalocean.com';
|
||||
const TOKEN = 'sometoken';
|
||||
const DIGITALOCEAN_ENDPOINT = 'https://api.digitalocean.com';
|
||||
|
||||
before(async function () {
|
||||
domainCopy.provider = 'digitalocean';
|
||||
@@ -61,7 +61,7 @@ describe('dns provider', function () {
|
||||
it('upsert non-existing record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 3352892,
|
||||
type: 'A',
|
||||
name: '@',
|
||||
@@ -71,10 +71,10 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.get('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(200, { domain_records: [] });
|
||||
let req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.post('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(201, { domain_record: DOMAIN_RECORD_0 });
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('dns provider', function () {
|
||||
it('upsert existing record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 3352892,
|
||||
type: 'A',
|
||||
name: '@',
|
||||
@@ -96,7 +96,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1 = {
|
||||
const DOMAIN_RECORD_1 = {
|
||||
id: 3352893,
|
||||
type: 'A',
|
||||
name: 'test',
|
||||
@@ -106,7 +106,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1_NEW = {
|
||||
const DOMAIN_RECORD_1_NEW = {
|
||||
id: 3352893,
|
||||
type: 'A',
|
||||
name: 'test',
|
||||
@@ -116,10 +116,10 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.get('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(200, { domain_records: [DOMAIN_RECORD_0, DOMAIN_RECORD_1] });
|
||||
let req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.put('/v2/domains/' + domainCopy.zoneName + '/records/' + DOMAIN_RECORD_1.id)
|
||||
.reply(200, { domain_record: DOMAIN_RECORD_1_NEW });
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('dns provider', function () {
|
||||
it('upsert multiple record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 3352892,
|
||||
type: 'A',
|
||||
name: '@',
|
||||
@@ -141,7 +141,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1 = {
|
||||
const DOMAIN_RECORD_1 = {
|
||||
id: 3352893,
|
||||
type: 'TXT',
|
||||
name: '@',
|
||||
@@ -151,7 +151,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1_NEW = {
|
||||
const DOMAIN_RECORD_1_NEW = {
|
||||
id: 3352893,
|
||||
type: 'TXT',
|
||||
name: '@',
|
||||
@@ -161,7 +161,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_2 = {
|
||||
const DOMAIN_RECORD_2 = {
|
||||
id: 3352894,
|
||||
type: 'TXT',
|
||||
name: '@',
|
||||
@@ -171,7 +171,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_2_NEW = {
|
||||
const DOMAIN_RECORD_2_NEW = {
|
||||
id: 3352894,
|
||||
type: 'TXT',
|
||||
name: '@',
|
||||
@@ -181,7 +181,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_3_NEW = {
|
||||
const DOMAIN_RECORD_3_NEW = {
|
||||
id: 3352895,
|
||||
type: 'TXT',
|
||||
name: '@',
|
||||
@@ -191,16 +191,16 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.get('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(200, { domain_records: [DOMAIN_RECORD_0, DOMAIN_RECORD_1, DOMAIN_RECORD_2] });
|
||||
let req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.put('/v2/domains/' + domainCopy.zoneName + '/records/' + DOMAIN_RECORD_1.id)
|
||||
.reply(200, { domain_record: DOMAIN_RECORD_1_NEW });
|
||||
let req3 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req3 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.put('/v2/domains/' + domainCopy.zoneName + '/records/' + DOMAIN_RECORD_2.id)
|
||||
.reply(200, { domain_record: DOMAIN_RECORD_2_NEW });
|
||||
let req4 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req4 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.post('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(201, { domain_record: DOMAIN_RECORD_2_NEW });
|
||||
|
||||
@@ -214,7 +214,7 @@ describe('dns provider', function () {
|
||||
it('get succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 3352892,
|
||||
type: 'A',
|
||||
name: '@',
|
||||
@@ -224,7 +224,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1 = {
|
||||
const DOMAIN_RECORD_1 = {
|
||||
id: 3352893,
|
||||
type: 'A',
|
||||
name: 'test',
|
||||
@@ -234,7 +234,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.get('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(200, { domain_records: [DOMAIN_RECORD_0, DOMAIN_RECORD_1] });
|
||||
|
||||
@@ -248,7 +248,7 @@ describe('dns provider', function () {
|
||||
it('del succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 3352892,
|
||||
type: 'A',
|
||||
name: '@',
|
||||
@@ -258,7 +258,7 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let DOMAIN_RECORD_1 = {
|
||||
const DOMAIN_RECORD_1 = {
|
||||
id: 3352893,
|
||||
type: 'A',
|
||||
name: 'test',
|
||||
@@ -268,10 +268,10 @@ describe('dns provider', function () {
|
||||
weight: null
|
||||
};
|
||||
|
||||
let req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req1 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.get('/v2/domains/' + domainCopy.zoneName + '/records')
|
||||
.reply(200, { domain_records: [DOMAIN_RECORD_0, DOMAIN_RECORD_1] });
|
||||
let req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
const req2 = nock(DIGITALOCEAN_ENDPOINT).filteringRequestBody(function () { return false; })
|
||||
.delete('/v2/domains/' + domainCopy.zoneName + '/records/' + DOMAIN_RECORD_1.id)
|
||||
.reply(204, {});
|
||||
|
||||
@@ -282,8 +282,8 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
describe('godaddy', function () {
|
||||
let KEY = 'somekey', SECRET = 'somesecret';
|
||||
let GODADDY_API = 'https://api.godaddy.com/v1/domains';
|
||||
const KEY = 'somekey', SECRET = 'somesecret';
|
||||
const GODADDY_API = 'https://api.godaddy.com/v1/domains';
|
||||
|
||||
before(async function () {
|
||||
domainCopy.provider = 'godaddy';
|
||||
@@ -298,12 +298,12 @@ describe('dns provider', function () {
|
||||
it('upsert record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = [{
|
||||
const DOMAIN_RECORD_0 = [{
|
||||
ttl: 600,
|
||||
data: '1.2.3.4'
|
||||
}];
|
||||
|
||||
let req1 = nock(GODADDY_API)
|
||||
const req1 = nock(GODADDY_API)
|
||||
.put('/' + domainCopy.zoneName + '/records/A/test', DOMAIN_RECORD_0)
|
||||
.reply(200, {});
|
||||
|
||||
@@ -314,12 +314,12 @@ describe('dns provider', function () {
|
||||
it('get succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = [{
|
||||
const DOMAIN_RECORD_0 = [{
|
||||
ttl: 600,
|
||||
data: '1.2.3.4'
|
||||
}];
|
||||
|
||||
let req1 = nock(GODADDY_API)
|
||||
const req1 = nock(GODADDY_API)
|
||||
.get('/' + domainCopy.zoneName + '/records/A/test')
|
||||
.reply(200, DOMAIN_RECORD_0);
|
||||
|
||||
@@ -333,21 +333,21 @@ describe('dns provider', function () {
|
||||
it('del succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = [{ // existing
|
||||
const DOMAIN_RECORD_0 = [{ // existing
|
||||
ttl: 600,
|
||||
data: '1.2.3.4'
|
||||
}];
|
||||
|
||||
let DOMAIN_RECORD_1 = [{ // replaced
|
||||
const DOMAIN_RECORD_1 = [{ // replaced
|
||||
ttl: 600,
|
||||
data: '0.0.0.0'
|
||||
}];
|
||||
|
||||
let req1 = nock(GODADDY_API)
|
||||
const req1 = nock(GODADDY_API)
|
||||
.get('/' + domainCopy.zoneName + '/records/A/test')
|
||||
.reply(200, DOMAIN_RECORD_0);
|
||||
|
||||
let req2 = nock(GODADDY_API)
|
||||
const req2 = nock(GODADDY_API)
|
||||
.put('/' + domainCopy.zoneName + '/records/A/test', DOMAIN_RECORD_1)
|
||||
.reply(200, {});
|
||||
|
||||
@@ -358,8 +358,8 @@ describe('dns provider', function () {
|
||||
});
|
||||
|
||||
describe('gandi', function () {
|
||||
let TOKEN = 'sometoken';
|
||||
let GANDI_API = 'https://dns.api.gandi.net/api/v5';
|
||||
const TOKEN = 'sometoken';
|
||||
const GANDI_API = 'https://dns.api.gandi.net/api/v5';
|
||||
|
||||
before(async function () {
|
||||
domainCopy.provider = 'gandi';
|
||||
@@ -373,12 +373,12 @@ describe('dns provider', function () {
|
||||
it('upsert record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
'rrset_ttl': 300,
|
||||
'rrset_values': ['1.2.3.4']
|
||||
};
|
||||
|
||||
let req1 = nock(GANDI_API)
|
||||
const req1 = nock(GANDI_API)
|
||||
.put('/domains/' + domainCopy.zoneName + '/records/test/A', DOMAIN_RECORD_0)
|
||||
.reply(201, { message: 'Zone Record Created' });
|
||||
|
||||
@@ -389,14 +389,14 @@ describe('dns provider', function () {
|
||||
it('get succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
'rrset_type': 'A',
|
||||
'rrset_ttl': 600,
|
||||
'rrset_name': 'test',
|
||||
'rrset_values': ['1.2.3.4']
|
||||
};
|
||||
|
||||
let req1 = nock(GANDI_API)
|
||||
const req1 = nock(GANDI_API)
|
||||
.get('/domains/' + domainCopy.zoneName + '/records/test/A')
|
||||
.reply(200, DOMAIN_RECORD_0);
|
||||
|
||||
@@ -410,7 +410,7 @@ describe('dns provider', function () {
|
||||
it('del succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let req2 = nock(GANDI_API)
|
||||
const req2 = nock(GANDI_API)
|
||||
.delete('/domains/' + domainCopy.zoneName + '/records/test/A')
|
||||
.reply(204, {});
|
||||
|
||||
@@ -436,18 +436,18 @@ describe('dns provider', function () {
|
||||
it('upsert record succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
host: 'test',
|
||||
type: 'A',
|
||||
answer: '1.2.3.4',
|
||||
ttl: 300
|
||||
};
|
||||
|
||||
let req1 = nock(NAMECOM_API)
|
||||
const req1 = nock(NAMECOM_API)
|
||||
.get(`/domains/${domainCopy.zoneName}/records`)
|
||||
.reply(200, { records: [] });
|
||||
|
||||
let req2 = nock(NAMECOM_API)
|
||||
const req2 = nock(NAMECOM_API)
|
||||
.post(`/domains/${domainCopy.zoneName}/records`, DOMAIN_RECORD_0)
|
||||
.reply(200, {});
|
||||
|
||||
@@ -459,14 +459,14 @@ describe('dns provider', function () {
|
||||
it('get succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
host: 'test',
|
||||
type: 'A',
|
||||
answer: '1.2.3.4',
|
||||
ttl: 300
|
||||
};
|
||||
|
||||
let req1 = nock(NAMECOM_API)
|
||||
const req1 = nock(NAMECOM_API)
|
||||
.get(`/domains/${domainCopy.zoneName}/records`)
|
||||
.reply(200, { records: [DOMAIN_RECORD_0] });
|
||||
|
||||
@@ -480,7 +480,7 @@ describe('dns provider', function () {
|
||||
it('del succeeds', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
let DOMAIN_RECORD_0 = {
|
||||
const DOMAIN_RECORD_0 = {
|
||||
id: 'someid',
|
||||
host: 'test',
|
||||
type: 'A',
|
||||
@@ -488,11 +488,11 @@ describe('dns provider', function () {
|
||||
ttl: 300
|
||||
};
|
||||
|
||||
let req1 = nock(NAMECOM_API)
|
||||
const req1 = nock(NAMECOM_API)
|
||||
.get(`/domains/${domainCopy.zoneName}/records`)
|
||||
.reply(200, { records: [DOMAIN_RECORD_0] });
|
||||
|
||||
let req2 = nock(NAMECOM_API)
|
||||
const req2 = nock(NAMECOM_API)
|
||||
.delete(`/domains/${domainCopy.zoneName}/records/${DOMAIN_RECORD_0.id}`)
|
||||
.reply(200, {});
|
||||
|
||||
@@ -554,7 +554,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -566,7 +566,7 @@ describe('dns provider', function () {
|
||||
})
|
||||
.reply(200, GET_HOSTS_RETURN);
|
||||
|
||||
let req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const expected = {
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -619,7 +619,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -631,7 +631,7 @@ describe('dns provider', function () {
|
||||
})
|
||||
.reply(200, GET_HOSTS_RETURN);
|
||||
|
||||
let req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const expected = {
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -694,7 +694,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -706,7 +706,7 @@ describe('dns provider', function () {
|
||||
})
|
||||
.reply(200, GET_HOSTS_RETURN);
|
||||
|
||||
let req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const expected = {
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -755,7 +755,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -791,7 +791,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -803,7 +803,7 @@ describe('dns provider', function () {
|
||||
})
|
||||
.reply(200, GET_HOSTS_RETURN);
|
||||
|
||||
let req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const req2 = nock(NAMECHEAP_ENDPOINT).post('/xml.response', (body) => {
|
||||
const expected = {
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -846,7 +846,7 @@ describe('dns provider', function () {
|
||||
<ExecutionTime>0.16</ExecutionTime>
|
||||
</ApiResponse>`;
|
||||
|
||||
let req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
const req1 = nock(NAMECHEAP_ENDPOINT).get('/xml.response')
|
||||
.query({
|
||||
ApiUser: username,
|
||||
ApiKey: token,
|
||||
@@ -866,7 +866,7 @@ describe('dns provider', function () {
|
||||
|
||||
describe('route53', function () {
|
||||
// do not clear this with [] but .length = 0 so we don't loose the reference in mockery
|
||||
let awsAnswerQueue = []; // every element itself is array: [0] is error and [1] is result
|
||||
const awsAnswerQueue = []; // every element itself is array: [0] is error and [1] is result
|
||||
|
||||
let AWS_HOSTED_ZONES = null;
|
||||
|
||||
@@ -1021,7 +1021,7 @@ describe('dns provider', function () {
|
||||
|
||||
describe('gcdns', function () {
|
||||
let HOSTED_ZONES = [];
|
||||
let zoneQueue = []; // every element itself is array: [0] is error and [1] is result
|
||||
const zoneQueue = []; // every element itself is array: [0] is error and [1] is result
|
||||
let _OriginalGCDNS;
|
||||
|
||||
before(async function () {
|
||||
|
||||
+80
-104
@@ -17,7 +17,7 @@ const BoxError = require('../boxerror.js'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
rimraf = require('rimraf'),
|
||||
recursive_readdir = require('recursive-readdir'),
|
||||
recursiveReaddir = require('recursive-readdir'),
|
||||
s3 = require('../storage/s3.js'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js'),
|
||||
@@ -150,25 +150,19 @@ describe('Storage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can remove file', function (done) {
|
||||
it('can remove file', async function () {
|
||||
const sourceFile = gTmpFolder + '/uploadtest/test-hardlink.txt';
|
||||
|
||||
filesystem.remove(gBackupConfig, sourceFile, function (error) {
|
||||
expect(error).to.be(null);
|
||||
expect(fs.existsSync(sourceFile)).to.be(false);
|
||||
done();
|
||||
});
|
||||
await filesystem.remove(gBackupConfig, sourceFile);
|
||||
expect(fs.existsSync(sourceFile)).to.be(false);
|
||||
});
|
||||
|
||||
it('can remove empty dir', function (done) {
|
||||
it('can remove empty dir', async function () {
|
||||
const sourceDir = gTmpFolder + '/emptydir';
|
||||
fs.mkdirSync(sourceDir);
|
||||
|
||||
filesystem.remove(gBackupConfig, sourceDir, function (error) {
|
||||
expect(error).to.be(null);
|
||||
expect(fs.existsSync(sourceDir)).to.be(false);
|
||||
done();
|
||||
});
|
||||
await filesystem.remove(gBackupConfig, sourceDir, () => {});
|
||||
expect(fs.existsSync(sourceDir)).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -206,18 +200,12 @@ describe('Storage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can remove file', function (done) {
|
||||
noop.remove(gBackupConfig, 'sourceFile', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('can remove file', async function () {
|
||||
await noop.remove(gBackupConfig, 'sourceFile');
|
||||
});
|
||||
|
||||
it('can remove empty dir', function (done) {
|
||||
noop.remove(gBackupConfig, 'sourceDir', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('can remove empty dir', async function () {
|
||||
await noop.remove(gBackupConfig, 'sourceDir', () => {});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -297,19 +285,13 @@ describe('Storage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can remove file', function (done) {
|
||||
s3.remove(gBackupConfig, 'uploadtest-copy/test.txt', function (error) {
|
||||
expect(error).to.be(null);
|
||||
expect(fs.existsSync(path.join(gS3Folder, 'uploadtest-copy/test.txt'))).to.be(false);
|
||||
done();
|
||||
});
|
||||
it('can remove file', async function () {
|
||||
await s3.remove(gBackupConfig, 'uploadtest-copy/test.txt');
|
||||
expect(fs.existsSync(path.join(gS3Folder, 'uploadtest-copy/test.txt'))).to.be(false);
|
||||
});
|
||||
|
||||
it('can remove non-existent dir', function (done) {
|
||||
noop.remove(gBackupConfig, 'blah', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('can remove non-existent dir', async function () {
|
||||
await noop.remove(gBackupConfig, 'blah', () => {});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -328,70 +310,71 @@ describe('Storage', function () {
|
||||
const GCSMockBasePath = path.join(os.tmpdir(), 'gcs-backup-test-buckets/');
|
||||
|
||||
before(function () {
|
||||
const mockGCS = function(){
|
||||
return {bucket: function(){
|
||||
const file = function(filename){
|
||||
const mockGCS = function() {
|
||||
return {
|
||||
bucket: function() {
|
||||
const file = function (filename) {
|
||||
function ensurePathWritable(filename) {
|
||||
filename = GCSMockBasePath + filename;
|
||||
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
||||
return filename;
|
||||
}
|
||||
|
||||
const ensurePathWritable = function (filename) {
|
||||
filename = GCSMockBasePath + filename;
|
||||
fs.mkdirSync(path.dirname(filename), { recursive: true });
|
||||
return filename;
|
||||
return {
|
||||
name: filename,
|
||||
createReadStream: function() {
|
||||
return fs.createReadStream(ensurePathWritable(filename))
|
||||
.on('error', function(e){
|
||||
console.log('error createReadStream: '+filename);
|
||||
if (e.code == 'ENOENT') { e.code = 404; }
|
||||
this.emit('error', e);
|
||||
})
|
||||
;
|
||||
},
|
||||
createWriteStream: function() {
|
||||
return fs.createWriteStream(ensurePathWritable(filename));
|
||||
},
|
||||
delete: async function() {
|
||||
await fs.promises.unlink(ensurePathWritable(filename));
|
||||
},
|
||||
copy: function(dst, cb) {
|
||||
function notFoundHandler(e) {
|
||||
if (e && e.code == 'ENOENT') { e.code = 404; return cb(e); }
|
||||
cb();
|
||||
}
|
||||
|
||||
return fs.createReadStream(ensurePathWritable(filename))
|
||||
.on('end', cb)
|
||||
.on('error', notFoundHandler)
|
||||
.pipe(fs.createWriteStream(ensurePathWritable(dst)))
|
||||
.on('end', cb)
|
||||
.on('error', notFoundHandler)
|
||||
;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
name: filename,
|
||||
createReadStream: function(){
|
||||
return fs.createReadStream(ensurePathWritable(filename))
|
||||
.on('error', function(e){
|
||||
console.log('error createReadStream: '+filename);
|
||||
if (e.code == 'ENOENT') { e.code = 404; }
|
||||
this.emit('error', e);
|
||||
})
|
||||
;
|
||||
},
|
||||
createWriteStream: function(){
|
||||
return fs.createWriteStream(ensurePathWritable(filename));
|
||||
},
|
||||
delete: function(cb){
|
||||
fs.unlink(ensurePathWritable(filename), cb);
|
||||
},
|
||||
copy: function(dst, cb){
|
||||
const notFoundHandler = function(e){
|
||||
if (e && e.code == 'ENOENT') { e.code = 404; return cb(e);}
|
||||
cb();
|
||||
};
|
||||
return fs.createReadStream(ensurePathWritable(filename))
|
||||
.on('end', cb)
|
||||
.on('error', notFoundHandler)
|
||||
.pipe(fs.createWriteStream(ensurePathWritable(dst)))
|
||||
.on('end', cb)
|
||||
.on('error', notFoundHandler)
|
||||
;
|
||||
file,
|
||||
|
||||
getFiles: function(q, cb) {
|
||||
const target = GCSMockBasePath + q.prefix;
|
||||
recursiveReaddir(target, function(e, files) {
|
||||
const pageToken = q.pageToken || 0;
|
||||
|
||||
const chunkedFiles = chunk(files, q.maxResults);
|
||||
if (q.pageToken >= chunkedFiles.length) return cb(null, []);
|
||||
|
||||
const gFiles = chunkedFiles[pageToken].map(function(f) {
|
||||
return file(path.relative(GCSMockBasePath, f)); //convert to gcs
|
||||
});
|
||||
|
||||
q.pageToken = pageToken + 1;
|
||||
cb(null, gFiles, q.pageToken < chunkedFiles.length ? q : null);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
file: file,
|
||||
getFiles: function(q, cb){
|
||||
const target = GCSMockBasePath + q.prefix;
|
||||
recursive_readdir(target, function(e, files){
|
||||
|
||||
const pageToken = q.pageToken || 0;
|
||||
|
||||
const chunkedFiles = chunk(files, q.maxResults);
|
||||
if (q.pageToken >= chunkedFiles.length) return cb(null, []);
|
||||
|
||||
const gFiles = chunkedFiles[pageToken].map(function(f){
|
||||
return file(path.relative(GCSMockBasePath, f)); //convert to google
|
||||
});
|
||||
|
||||
q.pageToken = pageToken + 1;
|
||||
cb(null, gFiles, q.pageToken < chunkedFiles.length ? q : null);
|
||||
});
|
||||
}
|
||||
};
|
||||
}};
|
||||
}};
|
||||
};
|
||||
gcs._mockInject(mockGCS);
|
||||
});
|
||||
@@ -451,20 +434,13 @@ describe('Storage', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can remove file', function (done) {
|
||||
gcs.remove(gBackupConfig, 'uploadtest-copy/test.txt', function (error) {
|
||||
expect(error).to.be(null);
|
||||
expect(fs.existsSync(path.join(GCSMockBasePath, 'uploadtest-copy/test.txt'))).to.be(false);
|
||||
done();
|
||||
});
|
||||
it('can remove file', async function () {
|
||||
await gcs.remove(gBackupConfig, 'uploadtest-copy/test.txt');
|
||||
expect(fs.existsSync(path.join(GCSMockBasePath, 'uploadtest-copy/test.txt'))).to.be(false);
|
||||
});
|
||||
|
||||
it('can remove non-existent dir', function (done) {
|
||||
gcs.remove(gBackupConfig, 'blah', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('can remove non-existent dir', async function () {
|
||||
await gcs.remove(gBackupConfig, 'blah', () => {});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user