Skip to content

Commit

Permalink
added delete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coen-hyde committed Aug 16, 2013
1 parent ca8062e commit 6dc8e91
Show file tree
Hide file tree
Showing 4 changed files with 58 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
2 changes: 1 addition & 1 deletion tasks/lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports.init = function (grunt) {
return options;
};

var makeClient = function(options) {
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 6dc8e91

Please sign in to comment.