Skip to content

Commit 69cfaf5

Browse files
author
Kerkesni
committed
replace hardcoded location names with global test variables
Replaced all instances of 'location-dmf-v1' and 'location-crr-v1' in test files with references to global constants Issue: CLDSRV-653
1 parent bad4440 commit 69cfaf5

File tree

15 files changed

+105
-40
lines changed

15 files changed

+105
-40
lines changed

tests/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const constants = {
2+
LOCATION_NAME_DMF: 'location-dmf-v1',
3+
LOCATION_NAME_CRR: 'location-crr-v1',
4+
};
5+
6+
module.exports = constants;

tests/functional/aws-node-sdk/test/bucket/getLocation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const withV4 = require('../support/withV4');
44
const BucketUtility = require('../../lib/utility/bucket-util');
55
const { config } = require('../../../../../lib/Config');
66

7+
const {
8+
LOCATION_NAME_DMF,
9+
} = require('../../../../constants');
10+
711
const bucketName = 'testgetlocationbucket';
812

913
const describeSkipAWS = process.env.AWS_ON_AIR ? describe.skip : describe;
@@ -22,7 +26,7 @@ describeSkipAWS('GET bucket location ', () => {
2226
// see next test.
2327
return;
2428
}
25-
if (location === 'location-dmf-v1') {
29+
if (location === LOCATION_NAME_DMF) {
2630
// if region location-dmf-v1 should return InvalidLocationConstraint error
2731
return;
2832
}

tests/functional/aws-node-sdk/test/bucket/put.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const getConfig = require('../support/config');
77
const withV4 = require('../support/withV4');
88
const configOfficial = require('../../../../../lib/Config').config;
99

10+
const {
11+
LOCATION_NAME_DMF,
12+
} = require('../../../../constants');
13+
1014
const bucketName = 'bucketlocation';
1115

1216
const describeSkipAWS = process.env.AWS_ON_AIR ? describe.skip : describe;
@@ -268,7 +272,7 @@ describe('PUT Bucket - AWS.S3.createBucket', () => {
268272
LocationConstraint: location,
269273
},
270274
}, err => {
271-
if (location === 'location-dmf-v1') {
275+
if (location === LOCATION_NAME_DMF) {
272276
assert.strictEqual(
273277
err.code,
274278
'InvalidLocationConstraint'
@@ -304,7 +308,7 @@ describe('PUT Bucket - AWS.S3.createBucket', () => {
304308
{
305309
Bucket: bucketName,
306310
CreateBucketConfiguration: {
307-
LocationConstraint: 'location-dmf-v1',
311+
LocationConstraint: LOCATION_NAME_DMF,
308312
},
309313
}, err => {
310314
assert.strictEqual(

tests/functional/aws-node-sdk/test/object/mpuVersion.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const { DummyRequestLogger } = require('../../../../unit/helpers');
88
const checkError = require('../../lib/utility/checkError');
99
const { getMetadata, fakeMetadataArchive } = require('../utils/init');
1010

11+
const {
12+
LOCATION_NAME_DMF,
13+
} = require('../../../../constants');
14+
1115
const log = new DummyRequestLogger();
1216

1317
const bucketName = 'bucket1putversion33';
@@ -847,17 +851,17 @@ describe('MPU with x-scal-s3-version-id header', () => {
847851
next => s3.listObjects({ Bucket: bucketName }, (err, res) => {
848852
assert.ifError(err);
849853
assert.strictEqual(res.Contents.length, 1);
850-
assert.strictEqual(res.Contents[0].StorageClass, 'location-dmf-v1');
854+
assert.strictEqual(res.Contents[0].StorageClass, LOCATION_NAME_DMF);
851855
return next();
852856
}),
853857
next => s3.headObject(params, (err, res) => {
854858
assert.ifError(err);
855-
assert.strictEqual(res.StorageClass, 'location-dmf-v1');
859+
assert.strictEqual(res.StorageClass, LOCATION_NAME_DMF);
856860
return next();
857861
}),
858862
next => s3.getObject(params, (err, res) => {
859863
assert.ifError(err);
860-
assert.strictEqual(res.StorageClass, 'location-dmf-v1');
864+
assert.strictEqual(res.StorageClass, LOCATION_NAME_DMF);
861865
return next();
862866
}),
863867
], err => {
@@ -957,7 +961,7 @@ describe('MPU with x-scal-s3-version-id header', () => {
957961
return next(err);
958962
}
959963
/* eslint-disable no-param-reassign */
960-
objMD.dataStoreName = 'location-dmf-v1';
964+
objMD.dataStoreName = LOCATION_NAME_DMF;
961965
objMD.archive = archive;
962966
objMD.replicationInfo = replicationInfo;
963967
// data related

tests/functional/aws-node-sdk/test/object/putVersion.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const { DummyRequestLogger } = require('../../../../unit/helpers');
88
const checkError = require('../../lib/utility/checkError');
99
const { getMetadata, fakeMetadataArchive } = require('../utils/init');
1010

11+
const {
12+
LOCATION_NAME_DMF,
13+
} = require('../../../../constants');
14+
1115
const log = new DummyRequestLogger();
1216

1317
const bucketName = 'bucket1putversion32';
@@ -753,24 +757,24 @@ describe('PUT object with x-scal-s3-version-id header', () => {
753757
next => s3.listObjects({ Bucket: bucketName }, (err, res) => {
754758
assert.ifError(err);
755759
assert.strictEqual(res.Contents.length, 1);
756-
assert.strictEqual(res.Contents[0].StorageClass, 'location-dmf-v1');
760+
assert.strictEqual(res.Contents[0].StorageClass, LOCATION_NAME_DMF);
757761
return next();
758762
}),
759763
next => s3.headObject(params, (err, res) => {
760764
assert.ifError(err);
761-
assert.strictEqual(res.StorageClass, 'location-dmf-v1');
765+
assert.strictEqual(res.StorageClass, LOCATION_NAME_DMF);
762766
return next();
763767
}),
764768
next => s3.getObject(params, (err, res) => {
765769
assert.ifError(err);
766-
assert.strictEqual(res.StorageClass, 'location-dmf-v1');
770+
assert.strictEqual(res.StorageClass, LOCATION_NAME_DMF);
767771
return next();
768772
}),
769773
], err => {
770774
assert.strictEqual(err, null, `Expected success got error ${JSON.stringify(err)}`);
771775

772776
// storage class must stay as the cold location
773-
assert.deepStrictEqual(objMDAfter['x-amz-storage-class'], 'location-dmf-v1');
777+
assert.deepStrictEqual(objMDAfter['x-amz-storage-class'], LOCATION_NAME_DMF);
774778

775779
/// Make sure object data location is set back to its bucket data location.
776780
assert.deepStrictEqual(objMDAfter.dataStoreName, 'us-east-1');
@@ -866,7 +870,7 @@ describe('PUT object with x-scal-s3-version-id header', () => {
866870
return next(err);
867871
}
868872
/* eslint-disable no-param-reassign */
869-
objMD.dataStoreName = 'location-dmf-v1';
873+
objMD.dataStoreName = LOCATION_NAME_DMF;
870874
objMD.archive = archive;
871875
objMD.replicationInfo = replicationInfo;
872876
// data related

tests/functional/aws-node-sdk/test/utils/init.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const log = new DummyRequestLogger();
77
const nonVersionedObjId =
88
versionIdUtils.getInfVid(config.replicationGroupId);
99

10+
const {
11+
LOCATION_NAME_DMF,
12+
} = require('../../../../constants');
13+
1014
function decodeVersionId(versionId) {
1115
let decodedVersionId;
1216
if (versionId) {
@@ -77,8 +81,8 @@ function fakeMetadataArchive(bucketName, objectName, versionId, archive, cb) {
7781
return cb(err);
7882
}
7983
/* eslint-disable no-param-reassign */
80-
objMD['x-amz-storage-class'] = 'location-dmf-v1';
81-
objMD.dataStoreName = 'location-dmf-v1';
84+
objMD['x-amz-storage-class'] = LOCATION_NAME_DMF;
85+
objMD.dataStoreName = LOCATION_NAME_DMF;
8286
objMD.archive = archive;
8387
/* eslint-enable no-param-reassign */
8488
return metadata.putObjectMD(bucketName, objectName, objMD, { versionId: decodeVersionId(versionId) },

tests/multipleBackend/backendHealthcheckResponse.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const {
1111
getAzureContainerName,
1212
} = require('../functional/aws-node-sdk/test/multipleBackend/utils');
1313

14+
const {
15+
LOCATION_NAME_DMF,
16+
LOCATION_NAME_CRR,
17+
} = require('../constants');
18+
1419
const log = new DummyRequestLogger();
1520
const locConstraints = Object.keys(config.locationConstraints);
1621
const azureClient = getAzureClient();
@@ -22,7 +27,7 @@ describe('Healthcheck response', () => {
2227
clientCheck(true, log, (err, results) => {
2328
const resultKeys = Object.keys(results);
2429
locConstraints.forEach(constraint => {
25-
if (constraint === 'location-dmf-v1' || constraint === 'location-crr-v1') {
30+
if (constraint === LOCATION_NAME_DMF || constraint === LOCATION_NAME_CRR) {
2631
// FIXME: location-dmf-v1 and location-crr-v1 are not in results, see CLDSRV-440
2732
return;
2833
}
@@ -45,7 +50,7 @@ describe('Healthcheck response', () => {
4550
clientCheck(false, log, (err, results) => {
4651
assert.notStrictEqual(results.length, locConstraints.length);
4752
locConstraints.forEach(constraint => {
48-
if (constraint === 'location-dmf-v1' || constraint === 'location-crr-v1') {
53+
if (constraint === LOCATION_NAME_DMF || constraint === LOCATION_NAME_CRR) {
4954
// FIXME: location-dmf-v1 and location-crr-v1 are not in results, see CLDSRV-440
5055
return;
5156
}

tests/unit/Config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const {
99
ConfigObject,
1010
} = require('../../lib/Config');
1111

12+
const {
13+
LOCATION_NAME_DMF,
14+
} = require('../constants');
15+
1216
const { ValidLifecycleRules: supportedLifecycleRules } = require('arsenal').models;
1317

1418
describe('Config', () => {
@@ -276,7 +280,7 @@ describe('Config', () => {
276280
'details': {},
277281
'isCold': true,
278282
'legacyAwsBehavior': false,
279-
'locationType': 'location-dmf-v1',
283+
'locationType': LOCATION_NAME_DMF,
280284
'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea',
281285
'type': 'tlp'
282286
},
@@ -291,7 +295,7 @@ describe('Config', () => {
291295
'details': {},
292296
'isCold': false,
293297
'legacyAwsBehavior': false,
294-
'locationType': 'location-dmf-v1',
298+
'locationType': LOCATION_NAME_DMF,
295299
'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea',
296300
'type': 'tlp'
297301
},
@@ -308,7 +312,7 @@ describe('Config', () => {
308312
},
309313
'isCold': true,
310314
'legacyAwsBehavior': false,
311-
'locationType': 'location-dmf-v1',
315+
'locationType': LOCATION_NAME_DMF,
312316
'objectId': 'b9d9b632-5fa5-11ef-8715-b21941dbc3ea',
313317
'type': 'tlp'
314318
},

tests/unit/api/apiUtils/coldStorage.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const { scaledMsPerDay } = config.getTimeOptions();
1313
const log = new DummyRequestLogger();
1414
const oneDay = 24 * 60 * 60 * 1000;
1515

16+
const {
17+
LOCATION_NAME_DMF,
18+
} = require('../../../constants');
19+
1620
describe('cold storage', () => {
1721
describe('validatePutVersionId', () => {
1822
[
@@ -42,14 +46,14 @@ describe('cold storage', () => {
4246
{
4347
description: 'should return InvalidObjectState if object is not archived',
4448
objMD: {
45-
dataStoreName: 'location-dmf-v1',
49+
dataStoreName: LOCATION_NAME_DMF,
4650
},
4751
expectedRes: errors.InvalidObjectState,
4852
},
4953
{
5054
description: 'should return InvalidObjectState if object is already restored',
5155
objMD: {
52-
dataStoreName: 'location-dmf-v1',
56+
dataStoreName: LOCATION_NAME_DMF,
5357
archive: {
5458
restoreRequestedAt: new Date(0),
5559
restoreRequestedDays: 5,
@@ -62,7 +66,7 @@ describe('cold storage', () => {
6266
{
6367
description: 'should pass if object archived',
6468
objMD: {
65-
dataStoreName: 'location-dmf-v1',
69+
dataStoreName: LOCATION_NAME_DMF,
6670
archive: {
6771
restoreRequestedAt: new Date(0),
6872
restoreRequestedDays: 5,
@@ -141,7 +145,7 @@ describe('cold storage', () => {
141145

142146
it('should fail when object is being restored', done => {
143147
const objectMd = new ObjectMD().setDataStoreName(
144-
'location-dmf-v1'
148+
LOCATION_NAME_DMF
145149
).setArchive(new ObjectMDArchive(
146150
{
147151
archiveId: '97a71dfe-49c1-4cca-840a-69199e0b0322',
@@ -159,7 +163,7 @@ describe('cold storage', () => {
159163

160164
it('should fail when restored object is expired', done => {
161165
const objectMd = new ObjectMD().setDataStoreName(
162-
'location-dmf-v1'
166+
LOCATION_NAME_DMF
163167
).setArchive(new ObjectMDArchive(
164168
{
165169
archiveId: '97a71dfe-49c1-4cca-840a-69199e0b0322',
@@ -179,7 +183,7 @@ describe('cold storage', () => {
179183

180184
it('should succeed for cold object', done => {
181185
const objectMd = new ObjectMD().setDataStoreName(
182-
'location-dmf-v1'
186+
LOCATION_NAME_DMF
183187
).setArchive(new ObjectMDArchive({
184188
archiveId: '97a71dfe-49c1-4cca-840a-69199e0b0322',
185189
archiveVersion: 5577006791947779,
@@ -204,7 +208,7 @@ describe('cold storage', () => {
204208

205209
it('should succeed for restored object', done => {
206210
const objectMd = new ObjectMD().setDataStoreName(
207-
'location-dmf-v1'
211+
LOCATION_NAME_DMF
208212
).setArchive(new ObjectMDArchive(
209213
{
210214
archiveId: '97a71dfe-49c1-4cca-840a-69199e0b0322',
@@ -246,7 +250,7 @@ describe('cold storage', () => {
246250

247251
it('should fail if _updateRestoreInfo fails', done => {
248252
const objectMd = new ObjectMD().setDataStoreName(
249-
'location-dmf-v1'
253+
LOCATION_NAME_DMF
250254
).setArchive(false).getValue();
251255

252256
startRestore(objectMd, { days: 7 }, log, err => {

tests/unit/api/bucketGetLocation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const { cleanup,
88
= require('../helpers');
99
const { config } = require('../../../lib/Config');
1010

11+
const {
12+
LOCATION_NAME_DMF,
13+
LOCATION_NAME_CRR,
14+
} = require('../../constants');
15+
1116
const log = new DummyRequestLogger();
1217
const authInfo = makeAuthInfo('accessKey1');
1318
const bucketName = 'bucketGetLocationTestBucket';
@@ -47,7 +52,7 @@ describe('getBucketLocation API', () => {
4752
// see next test.
4853
return;
4954
}
50-
if (location === 'location-dmf-v1' || location === 'location-crr-v1') {
55+
if (location === LOCATION_NAME_DMF || location === LOCATION_NAME_CRR) {
5156
// if region location-dmf-v1 or location-crr-v1 should return InvalidLocationConstraint error
5257
return;
5358
}

0 commit comments

Comments
 (0)