Skip to content

Commit

Permalink
CLDSRV-554 fix route metadata API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas2bert committed Jul 18, 2024
1 parent 9b77587 commit 0512c11
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions tests/functional/raw-node/test/routes/routeMetadata.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const assert = require('assert');
const http = require('http');

const { makeRequest } = require('../../utils/makeRequest');
const MetadataMock = require('../../utils/MetadataMock');
const { getCredentials } = require('../../../aws-node-sdk/test/support/credentials');
const BucketUtility = require('../../../aws-node-sdk/lib/utility/bucket-util');

const ipAddress = process.env.IP ? process.env.IP : 'localhost';
const metadataMock = new MetadataMock();

const { accessKeyId, secretAccessKey } = getCredentials();

Expand All @@ -33,14 +31,26 @@ function makeMetadataRequest(params, callback) {
}

describe('metadata routes with metadata mock backend', () => {
let httpServer;
const bucketUtil = new BucketUtility(
'default', { signatureVersion: 'v4' });
const s3 = bucketUtil.s3;

before(done => {
httpServer = http.createServer(
(req, res) => metadataMock.onRequest(req, res)).listen(9000, done);
});
const bucket1 = 'metadata-bucket1';
const bucket2 = 'metadata-bucket2';
const keyName = 'testobject1';

before(done => s3.createBucket({ Bucket: bucket1 }).promise()
.then(() => s3.putObject({ Bucket: bucket1, Key: keyName, Body: '' }).promise())
.then(() => s3.createBucket({ Bucket: bucket2 }).promise())
.then(() => done(), err => done(err))
);

after(() => httpServer.close());
after(done => bucketUtil.empty(bucket1)
.then(() => s3.deleteBucket({ Bucket: bucket1 }).promise())
.then(() => bucketUtil.empty(bucket2))
.then(() => s3.deleteBucket({ Bucket: bucket2 }).promise())
.then(() => done(), err => done(err))
);

it('should retrieve list of buckets', done => {
makeMetadataRequest({
Expand All @@ -51,7 +61,13 @@ describe('metadata routes with metadata mock backend', () => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 200);
assert(res.body);
assert.strictEqual(res.body, '["bucket1","bucket2"]');
const expectedArray = [bucket1, 'users..bucket', bucket2];
const responseArray = JSON.parse(res.body);

expectedArray.sort();
responseArray.sort();

assert.deepStrictEqual(responseArray, expectedArray);
return done();
});
});
Expand All @@ -60,7 +76,7 @@ describe('metadata routes with metadata mock backend', () => {
makeMetadataRequest({
method: 'GET',
authCredentials: metadataAuthCredentials,
path: '/_/metadata/default/bucket/bucket1',
path: `/_/metadata/default/bucket/${bucket1}`,
queryObj: { listingType: 'Delimiter' },
}, (err, res) => {
assert.ifError(err);
Expand All @@ -75,7 +91,7 @@ describe('metadata routes with metadata mock backend', () => {
makeMetadataRequest({
method: 'GET',
authCredentials: metadataAuthCredentials,
path: '/_/metadata/default/attributes/bucket1',
path: `/_/metadata/default/attributes/${bucket1}`,
}, (err, res) => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 200);
Expand All @@ -88,13 +104,13 @@ describe('metadata routes with metadata mock backend', () => {
makeMetadataRequest({
method: 'GET',
authCredentials: metadataAuthCredentials,
path: '/_/metadata/default/bucket/bucket1/testobject1',
path: `/_/metadata/default/bucket/${bucket1}/${keyName}`,
}, (err, res) => {
assert.ifError(err);
assert(res.body);
assert.strictEqual(res.statusCode, 200);
const body = JSON.parse(res.body);
assert.strictEqual(body.metadata, 'dogsAreGood');
assert(body['owner-id']);
return done();
});
});
Expand Down

0 comments on commit 0512c11

Please sign in to comment.