Skip to content

Commit

Permalink
Merge pull request pifantastic#92 from coen-hyde/delete-tests
Browse files Browse the repository at this point in the history
Added delete test
  • Loading branch information
pifantastic committed Aug 16, 2013
2 parents ca8062e + 003e81a commit 993cbaf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function (grunt) {
grunt.initConfig({
jshint: ['tasks/**/*.js'],
nodeunit: {
all: ['test/upload.js', 'test/download.js', 'test/s3Task.js', 'test/sync.js']
all: ['test/upload.js', 'test/download.js', 'test/delete.js', 'test/s3Task.js', 'test/sync.js']
},
clean: [ 's3/'],
s3: {
Expand Down
8 changes: 7 additions & 1 deletion tasks/lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ exports.init = function (grunt) {
return options;
};

var makeClient = function(options) {
/**
* Create an s3 client. Returns an Knox instance.
*
* @param {Object} Format.
* @returns {Object}
*/
var makeClient = exports.makeClient = function(options) {
return knox.createClient(_.pick(options, [
'region', 'endpoint', 'port', 'key', 'secret', 'access', 'bucket', 'secure', 'headers', 'style'
]));
Expand Down
55 changes: 55 additions & 0 deletions test/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

var grunt = require('grunt')
, fs = require('fs')

var hashFile = require('../tasks/lib/common').hashFile
, s3 = require('../tasks/lib/s3').init(grunt)
, _ = grunt.util._
, async = grunt.util.async
, s3Config = grunt.config("s3")
, common = require('./common')
, config = common.config;

module.exports = {
setUp: function(cb) {
async.series([
common.clean,
function(done) {
s3.upload(__dirname + '/files/a.txt', 'a.txt', common.config).done(done);
}
], function() {
cb();
});
},

testDelete: function(test) {
test.expect(4);

var dest = 'a.txt';
var client = s3.makeClient(config);

async.series([
function(next) {
client.getFile(dest, function (err, res) {
test.ifError(err);
test.equal(res.statusCode, 200, 'File exists.');
next();
});
},
function(next) {
s3.del(dest, config).done(function() {
next();
});
},
function(next) {
client.getFile(dest, function (err, res) {
test.ifError(err);
test.equal(res.statusCode, 404, 'File does not exist.');
next();
}, 500);
}
], function(err) {
test.done();
});
}
};
1 change: 1 addition & 0 deletions test/files/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a

0 comments on commit 993cbaf

Please sign in to comment.