New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated aws provider to invoke .promise on methods that support it. Otherwise falls back to .send with a callback #5161

Merged
merged 2 commits into from Jan 24, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+39 −6
Diff settings

Always

Just for now

@@ -271,10 +271,10 @@ class AwsProvider {
// TODO: Add listeners, put Debug statments here... // TODO: Add listeners, put Debug statments here...
// req.on('send', function (r) {console.log(r)}); // req.on('send', function (r) {console.log(r)});


return BbPromise.fromCallback(cb => { const promise = req.promise ? req.promise() : BbPromise.fromCallback(cb => {
req.send(cb); req.send(cb);
}) });
.catch(err => { return promise.catch(err => {
let message = err.message; let message = err.message;
if (err.message === 'Missing credentials in config') { if (err.message === 'Missing credentials in config') {
const errorMessage = [ const errorMessage = [
@@ -98,7 +98,7 @@ describe('AwsProvider', () => {
'${opt:stage, \'prod\'}', '${opt:stage, \'prod\'}',
]; ];
stages.forEach(stage => { stages.forEach(stage => {
it(`should not throw an error before variable population it(`should not throw an error before variable population
even if http event is present and stage is ${stage}`, () => { even if http event is present and stage is ${stage}`, () => {
const config = { const config = {
stage, stage,
@@ -286,6 +286,39 @@ describe('AwsProvider', () => {
}); });
}); });


it('should call correct aws method with a promise', () => {
// mocking API Gateway for testing
class FakeAPIGateway {
constructor(credentials) {
this.credentials = credentials;
}

getRestApis() {
return {
promise: () => BbPromise.resolve({ called: true }),
};
}
}
awsProvider.sdk = {
APIGateway: FakeAPIGateway,
};
awsProvider.serverless.service.environment = {
vars: {},
stages: {
dev: {
vars: {
profile: 'default',
},
regions: {},
},
},
};

return awsProvider.request('APIGateway', 'getRestApis', {}).then(data => {
expect(data.called).to.equal(true);
});
});



it('should request to the specified region if region in options set', () => { it('should request to the specified region if region in options set', () => {
// mocking S3 for testing // mocking S3 for testing
@@ -316,7 +349,7 @@ describe('AwsProvider', () => {
}, },
}, },
}; };
expect(awsProvider.getCredentials()).to.deep.eql({ region: options.region }); expect(awsProvider.getCredentials().region).to.eql(options.region);


return awsProvider return awsProvider
.request('CloudFormation', .request('CloudFormation',
@@ -326,7 +359,7 @@ describe('AwsProvider', () => {
.then(data => { .then(data => {
expect(data).to.eql({ region: 'ap-northeast-1' }); expect(data).to.eql({ region: 'ap-northeast-1' });
// Requesting different region should not affect region in credentials // Requesting different region should not affect region in credentials
expect(awsProvider.getCredentials()).to.deep.eql({ region: options.region }); expect(awsProvider.getCredentials().region).to.eql(options.region);
}); });
}); });
it('should retry if error code is 429', (done) => { it('should retry if error code is 429', (done) => {
ProTip! Use n and p to navigate between commits in a pull request.