diff --git a/Gruntfile.js b/Gruntfile.js index a375354..1a56b96 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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: { diff --git a/tasks/lib/s3.js b/tasks/lib/s3.js index e975333..02b7408 100644 --- a/tasks/lib/s3.js +++ b/tasks/lib/s3.js @@ -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' ])); diff --git a/test/delete.js b/test/delete.js new file mode 100644 index 0000000..ca95975 --- /dev/null +++ b/test/delete.js @@ -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(); + }); + } +}; \ No newline at end of file diff --git a/test/files/a.txt b/test/files/a.txt index e69de29..2e65efe 100644 --- a/test/files/a.txt +++ b/test/files/a.txt @@ -0,0 +1 @@ +a \ No newline at end of file