Skip to content

Commit

Permalink
Implemented custom metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Hall committed Jan 28, 2015
1 parent 50ee67b commit dc08729
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : 7, // {int} Max cyclomatic complexity per function
"maxcomplexity" : 8, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
Expand Down
9 changes: 7 additions & 2 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ module.exports = function (rootDirectory, logger) {
*/
if ((/^[a-z0-9]+(-[a-z0-9]+)*$/.test(bucketName) === false)) {
template = templateBuilder.buildError('InvalidBucketName',
'Bucket names can contain lowercase letters, numbers, and hyphens. ' +
'Each label must start and end with a lowercase letter or a number.');
'Bucket names can contain lowercase letters, numbers, and hyphens. ' +
'Each label must start and end with a lowercase letter or a number.');
return buildXmlResponse(res, 400, template);
}
if (bucketName.length < 3 || bucketName.length > 63) {
Expand Down Expand Up @@ -125,6 +125,11 @@ module.exports = function (rootDirectory, logger) {
res.header('Last-Modified', new Date(object.modifiedDate).toUTCString());
res.header('Content-Type', object.contentType);
res.header('Content-Length', object.size);
if (object.customMetaData.length > 0) {
object.customMetaData.forEach(function (metaData) {
res.header(metaData.key, metaData.value);
});
}
res.status(200);
if (req.method === 'HEAD') {
return res.end();
Expand Down
7 changes: 5 additions & 2 deletions lib/file-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ var FileStore = function (rootDirectory) {
var customMetaData = [];
for (var header in headers) {
if (/^x-amz-meta-(.*)$/.test(header)) {
customMetaData.push(header);
customMetaData.push({
key: header,
value: headers[header]
});
}
}
return customMetaData;
Expand Down Expand Up @@ -188,7 +191,7 @@ var FileStore = function (rootDirectory) {
size: results[1].size,
modifiedDate: results[0].mtime,
creationDate: results[0].ctime,
customMetadata: getCustomMetaData(headers)
customMetaData: getCustomMetaData(headers)
};
fs.writeFile(metaFile, JSON.stringify(metaData), function (err) {
if(err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/models/s3-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var S3Object = function (s3Item) {
size: s3Item.size,
modifiedDate: s3Item.modifiedDate,
creationDate: s3Item.creationDate,
customMetaData: s3Item.customMetadata
customMetaData: s3Item.customMetaData
};
return item;
};
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ describe('S3rver Tests', function () {
});
});

it('should store a text object with some custom metadata', function (done) {
var params = {
Bucket: buckets[0], Key: 'textmetadata', Body: 'Hello!', Metadata: {
someKey: 'value'
}
};
s3Client.putObject(params, function (err, data) {
/[a-fA-F0-9]{32}/.test(data.ETag).should.equal(true);
if (err) {
return done(err);
}
done();
});
});

it('should return a text object with some custom metadata', function (done) {
s3Client.getObject({Bucket: buckets[0], Key: 'textmetadata'}, function (err, object) {
if (err) {
return done(err);
}
object.Metadata.somekey.should.equal('value');
done();
});
});

it('should store an image in a bucket', function (done) {
var file = path.join(__dirname, 'resources/image.jpg');
fs.readFile(file, function (err, data) {
Expand Down

0 comments on commit dc08729

Please sign in to comment.