Skip to content

Commit

Permalink
Merge pull request #24 from achambers/make-region-mandatory
Browse files Browse the repository at this point in the history
Make region a required property
  • Loading branch information
lukemelia committed Oct 30, 2015
2 parents 84567df + ad7c26c commit 7c1fc45
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The AWS bucket that the files will be uploaded to.

The region the AWS `bucket` is located in.

*Default:* `us-east-1`
*Default:* `undefined`

### prefix

Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
region: 'us-east-1',
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2}',
prefix: '',
distDir: function(context) {
Expand All @@ -35,7 +34,7 @@ module.exports = {
return context.s3Client; // if you want to provide your own S3 client to be used instead of one from aws-sdk
}
},
requiredConfig: ['accessKeyId', 'secretAccessKey', 'bucket'],
requiredConfig: ['accessKeyId', 'secretAccessKey', 'bucket', 'region'],

upload: function(context) {
var self = this;
Expand Down
102 changes: 81 additions & 21 deletions tests/unit/index-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ describe('s3 plugin', function() {
plugin.configure(context);
});
});

it('warns about missing optional config', function() {
delete context.config.s3.region;
delete context.config.s3.filePattern;
delete context.config.s3.prefix;

Expand All @@ -119,38 +119,99 @@ describe('s3 plugin', function() {
return previous;
}, []);

assert.equal(messages.length, 3);
assert.equal(messages.length, 2);
});

it('warns about missing required config', function() {
delete context.config.s3.accessKeyId;
delete context.config.s3.secretAccessKey;
delete context.config.s3.bucket;
describe('reaquired config', function() {
it('warns about missing accessKeyId', function() {
delete context.config.s3.accessKeyId;

var plugin = subject.createDeployPlugin({
name: 's3'
var plugin = subject.createDeployPlugin({
name: 's3'
});
plugin.beforeHook(context);
assert.throws(function(error){
plugin.configure(context);
});
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing required config: `accessKeyId`/.test(current)) {
previous.push(current);
}

return previous;
}, []);

assert.equal(messages.length, 1);
});
plugin.beforeHook(context);
assert.throws(function(error){
plugin.configure(context);

it('warns about missing secretAccessKey', function() {
delete context.config.s3.secretAccessKey;

var plugin = subject.createDeployPlugin({
name: 's3'
});
plugin.beforeHook(context);
assert.throws(function(error){
plugin.configure(context);
});
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing required config: `secretAccessKey`/.test(current)) {
previous.push(current);
}

return previous;
}, []);

assert.equal(messages.length, 1);
});
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing required config:\s.*/.test(current)) {
previous.push(current);
}

return previous;
}, []);
it('warns about missing bucket', function() {
delete context.config.s3.bucket;

var plugin = subject.createDeployPlugin({
name: 's3'
});
plugin.beforeHook(context);
assert.throws(function(error){
plugin.configure(context);
});
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing required config: `bucket`/.test(current)) {
previous.push(current);
}

return previous;
}, []);

assert.equal(messages.length, 1); // doesn't log all failures, just first one
assert.equal(messages.length, 1);
});

it('warns about missing region', function() {
delete context.config.s3.region;

var plugin = subject.createDeployPlugin({
name: 's3'
});
plugin.beforeHook(context);
assert.throws(function(error){
plugin.configure(context);
});
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing required config: `region`/.test(current)) {
previous.push(current);
}

return previous;
}, []);

assert.equal(messages.length, 1);
});
});

it('adds default config to the config object', function() {
delete context.config.s3.region;
delete context.config.s3.filePattern;
delete context.config.s3.prefix;

assert.isUndefined(context.config.s3.region);
assert.isUndefined(context.config.s3.filePattern);
assert.isUndefined(context.config.s3.prefix);

Expand All @@ -160,7 +221,6 @@ describe('s3 plugin', function() {
plugin.beforeHook(context);
plugin.configure(context);

assert.isDefined(context.config.s3.region);
assert.isDefined(context.config.s3.filePattern);
assert.isDefined(context.config.s3.prefix);
});
Expand Down

0 comments on commit 7c1fc45

Please sign in to comment.