Skip to content

Commit 90ea727

Browse files
authored
Merge pull request #133 from serverless/fix-default-region-setting
Fix default region setting
2 parents 39f4d83 + 3857c1a commit 90ea727

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

shared/utils.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ const BbPromise = require('bluebird');
55

66
module.exports = {
77
setDefaults() {
8-
this.options.stage = _.get(this, 'options.stage')
9-
|| 'dev';
10-
this.options.runtime = _.get(this, 'options.runtime')
11-
|| 'nodejs8';
8+
this.options.stage = _.get(this, 'options.stage') || 'dev';
9+
this.options.runtime = _.get(this, 'options.runtime') || 'nodejs8';
1210

1311
// serverless framework is hard-coding us-east-1 region from aws
1412
// this is temporary fix for multiple regions
15-
const region = _.get(this, 'options.region')
16-
|| _.get(this, 'serverless.service.provider.region');
13+
let region = _.get(this, 'options.region') || _.get(this, 'serverless.service.provider.region');
1714

18-
this.options.region = (!region || region === 'us-east-1')
19-
? 'us-central1' : region;
15+
if (region === 'us-east-1') {
16+
region = 'us-central1';
17+
}
18+
19+
this.options.region = region;
20+
this.serverless.service.provider.region = region;
2021

2122
return BbPromise.resolve();
2223
},

shared/utils.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ describe('Utils', () => {
1313
serverless = new Serverless();
1414
serverless.setProvider('google', new GoogleProvider(serverless));
1515
googleCommand = new GoogleCommand(serverless, {}, setDefaults);
16+
// mocking the standard value passed in from Serverless here
17+
googleCommand.serverless.service.provider = {
18+
region: 'us-east-1',
19+
};
1620
});
1721

1822
describe('#setDefaults()', () => {
@@ -45,5 +49,10 @@ describe('Utils', () => {
4549
expect(googleCommand.options.region).toEqual('my-region');
4650
});
4751
});
52+
53+
it('shoud default to the us-central1 region when no region is provided', () => googleCommand
54+
.setDefaults().then(() => {
55+
expect(googleCommand.options.region).toEqual('us-central1');
56+
}));
4857
});
4958
});

0 commit comments

Comments
 (0)