mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Merge pull request #5161 from kalarrs/master
Updated aws provider to invoke .promise on methods that support it. Otherwise falls back to .send with a callback
This commit is contained in:
commit
dfb36b8503
@ -271,10 +271,10 @@ class AwsProvider {
|
||||
// TODO: Add listeners, put Debug statments here...
|
||||
// req.on('send', function (r) {console.log(r)});
|
||||
|
||||
return BbPromise.fromCallback(cb => {
|
||||
const promise = req.promise ? req.promise() : BbPromise.fromCallback(cb => {
|
||||
req.send(cb);
|
||||
})
|
||||
.catch(err => {
|
||||
});
|
||||
return promise.catch(err => {
|
||||
let message = err.message;
|
||||
if (err.message === 'Missing credentials in config') {
|
||||
const errorMessage = [
|
||||
|
||||
@ -98,7 +98,7 @@ describe('AwsProvider', () => {
|
||||
'${opt:stage, \'prod\'}',
|
||||
];
|
||||
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}`, () => {
|
||||
const config = {
|
||||
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', () => {
|
||||
// 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
|
||||
.request('CloudFormation',
|
||||
@ -326,7 +359,7 @@ describe('AwsProvider', () => {
|
||||
.then(data => {
|
||||
expect(data).to.eql({ region: 'ap-northeast-1' });
|
||||
// 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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user