Skip to content

Commit

Permalink
Merge pull request pifantastic#87 from coen-hyde/fix-tests
Browse files Browse the repository at this point in the history
Fixed tests for newer version of knox that specifies bucket as virtualhost instead of paths
  • Loading branch information
pifantastic committed Aug 15, 2013
2 parents 568b603 + 33630fb commit 9f89923
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
9 changes: 7 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function (grunt) {
nodeunit: {
all: ['test/upload.js', 'test/download.js', 'test/s3Task.js']
},
clean: [ 's3/'],
s3: {
options: {
key: 'abc',
Expand All @@ -15,7 +16,8 @@ module.exports = function (grunt) {
endpoint: '127.0.0.1',
port: 1337,
secure: false,
access: 'public-read'
access: 'public-read',
style: 'path'
},
test: {
options: {}
Expand All @@ -39,6 +41,9 @@ module.exports = function (grunt) {

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.registerTask('test', ['jshint', 'nodeunit']);
grunt.loadNpmTasks('grunt-contrib-clean');

grunt.registerTask('test', ['clean', 'jshint', 'nodeunit']);

grunt.loadTasks(__dirname + '/tasks');
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "grunt-s3",
"description": "A grunt task to automate moving files to/from Amazon S3.",
"version": "0.2.0-alpha.2",
Expand All @@ -20,7 +20,8 @@
"main": "tasks/s3",
"bin": "bin/grunt-s3",
"scripts": {
"test": "grunt test"
"test": "grunt test",
"fakes3": "fakes3 -r s3 -p 1337"
},
"engines": {
"node": ">= 0.8.0"
Expand All @@ -41,6 +42,7 @@
"nodeunit": "~0.7.4",
"grunt-contrib-jshint": "~0.1.0",
"grunt-contrib-nodeunit": "~0.1.1",
"libyaml": "~0.2.1"
"libyaml": "~0.2.1",
"grunt-contrib-clean": "~0.5.0"
}
}
42 changes: 22 additions & 20 deletions tasks/lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ exports.init = function (grunt) {
return new Error(msg);
};

var makeOptions = exports.makeOptions = function(opts) {
var options = _.clone(opts || {}, true);

return options;
};

var makeClient = function(options) {
return knox.createClient(_.pick(options, [
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket', 'secure', 'headers', 'style'
]));
};

/**
* Publishes the local file at src to the s3 dest.
*
Expand All @@ -84,7 +96,7 @@ exports.init = function (grunt) {
*/
exports.put = exports.upload = function (src, dest, opts) {
var dfd = new _.Deferred();
var options = _.clone(opts, true);
var options = makeOptions(opts);

// Make sure the local file exists.
if (!existsSync(src)) {
Expand All @@ -98,9 +110,7 @@ exports.init = function (grunt) {
}

// Pick out the configuration options we need for the client.
var client = knox.createClient(_(options).pick([
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket', 'secure'
]));
var client = makeClient(options);

if (options.debug) {
return dfd.resolve(util.format(MSG_UPLOAD_DEBUG, path.relative(process.cwd(), src), client.bucket, dest)).promise();
Expand Down Expand Up @@ -216,12 +226,10 @@ exports.init = function (grunt) {
*/
exports.pull = exports.download = function (src, dest, opts) {
var dfd = new _.Deferred();
var options = _.clone(opts);
var options = makeOptions(opts);

// Pick out the configuration options we need for the client.
var client = knox.createClient(_(options).pick([
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket'
]));
var client = makeClient(options);

if (options.debug) {
return dfd.resolve(util.format(MSG_DOWNLOAD_DEBUG, client.bucket, src, path.relative(process.cwd(), dest))).promise();
Expand Down Expand Up @@ -288,12 +296,10 @@ exports.init = function (grunt) {
*/
exports.copy = function (src, dest, opts) {
var dfd = new _.Deferred();
var options = _.clone(opts);
var options = makeOptions(opts);

// Pick out the configuration options we need for the client.
var client = knox.createClient(_(options).pick([
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket'
]));
var client = makeClient(options);

if (options.debug) {
return dfd.resolve(util.format(MSG_COPY_DEBUG, src, client.bucket, dest)).promise();
Expand Down Expand Up @@ -334,12 +340,10 @@ exports.init = function (grunt) {
*/
exports.del = function (src, opts) {
var dfd = new _.Deferred();
var options = _.clone(opts);
var options = makeOptions(opts);

// Pick out the configuration options we need for the client.
var client = knox.createClient(_(options).pick([
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket'
]));
var client = makeClient(options);

if (options.debug) {
return dfd.resolve(util.format(MSG_DELETE_DEBUG, client.bucket, src)).promise();
Expand Down Expand Up @@ -374,12 +378,10 @@ exports.init = function (grunt) {
*/
exports.sync = function (src, dest, opts) {
var dfd = new _.Deferred();
var options = _.clone(opts);
var options = makeOptions(opts);

// Pick out the configuration options we need for the client.
var client = knox.createClient(_(options).pick([
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket'
]));
var client = makeClient(options);

if (options.debug) {
return dfd.resolve(util.format(MSG_SKIP_DEBUG, client.bucket, src)).promise();
Expand Down
4 changes: 2 additions & 2 deletions test/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
test.expect(1);

var dest = __dirname + '/files/a.txt';
var src = __dirname + '/../s3/127/a.txt/.fakes3_metadataFFF/content';
var src = __dirname + '/../s3/127/test/a.txt/.fakes3_metadataFFF/content';

s3.download('a.txt', dest, config)
.done(function () {
Expand All @@ -28,7 +28,7 @@ module.exports = {
test.expect(1);

var dest = __dirname + '/files/b.txt.debug';
var src = __dirname + '/../s3/127/b.txt/.fakes3_metadataFFF/content';
var src = __dirname + '/../s3/127/test/b.txt/.fakes3_metadataFFF/content';

var debugConfig = _.defaults({}, config, {debug: true});

Expand Down
20 changes: 8 additions & 12 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = {
testUpload : function (test) {
test.expect(2);

async.waterfall([
async.series([
function (cb) {
var src = __dirname + '/files/a.txt';
var dest = __dirname + '/../s3/127/a.txt/.fakes3_metadataFFF/content';
var dest = __dirname + '/../s3/127/test/a.txt/.fakes3_metadataFFF/content';

s3.upload(src, 'a.txt', config)
.done(function () {
Expand All @@ -36,38 +36,34 @@ module.exports = {
cb(null);
});
}
], function () {
test.done();
});
], test.done);
},

testUploadWithHeaders : function (test) {
test.expect(1);

async.waterfall([
async.series([
function (cb) {
var src = __dirname + '/files/b.txt';
var dest = __dirname + '/../s3/127/b.txt/.fakes3_metadataFFF/metadata';
var dest = __dirname + '/../s3/127/test/b.txt/.fakes3_metadataFFF/metadata';

var headerConfig = _.defaults({}, config, { headers : {'Content-Type' : '<3'} });

s3.upload(src, 'b.txt', headerConfig)
.always(function () {
var meta = yaml.parse(grunt.file.read(dest))
var meta = yaml.parse(grunt.file.read(dest));
test.ok(meta[0][':content_type'] === new Buffer('<3').toString('base64'), 'Headers are preserved.');
cb(null);
});
}
], function () {
test.done();
});
], test.done);
},

testUploadDebug : function (test) {
test.expect(1);

var src = __dirname + '/files/c.txt';
var dest = __dirname + '/../s3/127/c.txt/.fakes3_metadataFFF/content';
var dest = __dirname + '/../s3/127/test/c.txt/.fakes3_metadataFFF/content';

var debugConfig = _.defaults({}, config, { debug: true });

Expand Down

0 comments on commit 9f89923

Please sign in to comment.