From aea24abd532f2e90b24ebebeb898b25415093342 Mon Sep 17 00:00:00 2001 From: Coen Hyde Date: Thu, 15 Aug 2013 13:39:44 -0700 Subject: [PATCH] enabled sync tests and fixed them --- Gruntfile.js | 2 +- package.json | 3 ++- test/common.js | 15 ++++++++++++ test/download.js | 17 ++++++++++++-- test/files/a.txt | 1 - test/s3Task.js | 6 +++-- test/sync.js | 60 ++++++++++++++++++++++++------------------------ test/upload.js | 7 ++++-- 8 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 test/common.js diff --git a/Gruntfile.js b/Gruntfile.js index af52899..a375354 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'] + all: ['test/upload.js', 'test/download.js', 'test/s3Task.js', 'test/sync.js'] }, clean: [ 's3/'], s3: { diff --git a/package.json b/package.json index 0db7f9b..0619d64 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "grunt-contrib-jshint": "~0.1.0", "grunt-contrib-nodeunit": "~0.1.1", "libyaml": "~0.2.1", - "grunt-contrib-clean": "~0.5.0" + "grunt-contrib-clean": "~0.5.0", + "rimraf": "~2.2.2" } } diff --git a/test/common.js b/test/common.js new file mode 100644 index 0000000..c52c332 --- /dev/null +++ b/test/common.js @@ -0,0 +1,15 @@ + +var grunt = require('grunt') + , rimraf = require('rimraf') + , s3 = require('../tasks/lib/s3').init(grunt) + , s3Config = grunt.config("s3") + , _ = grunt.util._ + , async = grunt.util.async; + +var common = module.exports = { + config: _.extend({}, s3Config.options, s3Config.test.options), + + clean: function(cb) { + rimraf(__dirname + '/../s3', cb); + } +} \ No newline at end of file diff --git a/test/download.js b/test/download.js index a790667..7422268 100644 --- a/test/download.js +++ b/test/download.js @@ -4,11 +4,24 @@ var hashFile = require('../tasks/lib/common').hashFile; var s3 = require('../tasks/lib/s3').init(grunt); var _ = grunt.util._; +var async = grunt.util.async; -var s3Config = grunt.config("s3"), - config = _.extend({}, s3Config.options, s3Config.test.options); +var 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(); + }); + }, + testDownload : function (test) { test.expect(1); diff --git a/test/files/a.txt b/test/files/a.txt index 7898192..e69de29 100644 --- a/test/files/a.txt +++ b/test/files/a.txt @@ -1 +0,0 @@ -a diff --git a/test/s3Task.js b/test/s3Task.js index 0fca3ec..1c2b6f2 100644 --- a/test/s3Task.js +++ b/test/s3Task.js @@ -8,8 +8,9 @@ var async = grunt.util.async; var _ = grunt.util._; _.mixin(deferred); -var s3Config = grunt.config('s3'); -var config = _.extend({}, s3Config.options, s3Config.test_S3Task.options); +var s3Config = grunt.config("s3") + , common = require('./common') + , config = common.config; var makeMockTask = function (taskDef) { // A fake grunt task @@ -35,6 +36,7 @@ var makeMockTask = function (taskDef) { }; module.exports = { + setUp: common.clean, run: function (test) { var taskDef = new _.Deferred(); var asyncCalls = 0; diff --git a/test/sync.js b/test/sync.js index e553a78..2a21fee 100644 --- a/test/sync.js +++ b/test/sync.js @@ -7,37 +7,37 @@ var s3 = require('../tasks/lib/s3').init(grunt); var _ = grunt.util._; var async = grunt.util.async; -var s3Config = grunt.config("s3"), - config = _.extend({}, s3Config.options, s3Config.test.options); +var s3Config = grunt.config("s3") + , common = require('./common') + , config = common.config; module.exports = { - testSync : function (test) { - test.expect(2); - - async.waterfall([ - function (cb) { - var src = __dirname + '/files/a.txt'; - var dest = __dirname + '/../s3/127/a.txt/.fakes3_metadataFFF/content'; - - s3.sync(src, 'a.txt', config) - .done(function () { - test.ok(hashFile(src) === hashFile(dest), 'File uploaded successfully.'); - }) - .always(function () { - cb(null); - }); - }, - function (cb) { - s3.sync('./src does not exist', './dest does not matter') - .fail(function (err) { - test.ok(err, 'Missing source results in an error.'); - }) - .always(function () { - cb(null); - }); - } - ], function () { - test.done(); - }); + setUp: common.clean, + + testSync: function (test) { + test.expect(1); + + var src = __dirname + '/files/a.txt'; + var dest = __dirname + '/../s3/127/test/a.txt/.fakes3_metadataFFF/content'; + + s3.sync(src, 'a.txt', config) + .done(function () { + test.ok(hashFile(src) === hashFile(dest), 'File uploaded successfully.'); + }) + .always(function () { + test.done(); + }); + }, + + testSyncInvalidSrc: function(test) { + test.expect(1); + + s3.sync('./src does not exist', './dest does not matter', config) + .fail(function (err) { + test.ok(err, 'Missing source results in an error.'); + }) + .always(function () { + test.done(); + }); } }; diff --git a/test/upload.js b/test/upload.js index 184cdaa..40addaa 100644 --- a/test/upload.js +++ b/test/upload.js @@ -7,10 +7,13 @@ var s3 = require('../tasks/lib/s3').init(grunt); var _ = grunt.util._; var async = grunt.util.async; -var s3Config = grunt.config("s3"), - config = _.extend({}, s3Config.options, s3Config.test.options); +var s3Config = grunt.config("s3") + , common = require('./common') + , config = common.config; module.exports = { + setUp: common.clean, + testUpload : function (test) { test.expect(2);