Skip to content

Commit

Permalink
Merge pull request pifantastic#89 from coen-hyde/sync-tests
Browse files Browse the repository at this point in the history
Enabled sync tests and fixed them
  • Loading branch information
pifantastic committed Aug 15, 2013
2 parents a97ef68 + aea24ab commit dc9f543
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 39 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']
all: ['test/upload.js', 'test/download.js', 'test/s3Task.js', 'test/sync.js']
},
clean: [ 's3/'],
s3: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 15 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 15 additions & 2 deletions test/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion test/files/a.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
a
6 changes: 4 additions & 2 deletions test/s3Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +36,7 @@ var makeMockTask = function (taskDef) {
};

module.exports = {
setUp: common.clean,
run: function (test) {
var taskDef = new _.Deferred();
var asyncCalls = 0;
Expand Down
60 changes: 30 additions & 30 deletions test/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
};
7 changes: 5 additions & 2 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit dc9f543

Please sign in to comment.