Skip to content

Commit

Permalink
Merge pull request #4537 from serverless/fix-resolve-signature-and-calls
Browse files Browse the repository at this point in the history
Remove not used parameters from request() and add options hive
  • Loading branch information
horike37 committed Dec 11, 2017
2 parents 24ce96d + e4a5a1d commit 1fb90f6
Show file tree
Hide file tree
Showing 39 changed files with 215 additions and 411 deletions.
12 changes: 3 additions & 9 deletions lib/classes/Variables.js
Expand Up @@ -352,9 +352,7 @@ class Variables {
.request('CloudFormation',
'describeStacks',
{ StackName: stackName },
this.options.stage,
this.options.region,
true // Use request cache
{ useCache: true } // Use request cache
)
.then(result => {
const outputs = result.Stacks[0].Outputs;
Expand Down Expand Up @@ -385,9 +383,7 @@ class Variables {
Bucket: bucket,
Key: key,
},
this.options.stage,
this.options.region,
true // Use request cache
{ useCache: true } // Use request cache
)
.then(
response => response.Body.toString(),
Expand All @@ -409,9 +405,7 @@ class Variables {
Name: param,
WithDecryption: decrypt,
},
this.options.stage,
this.options.region,
true // Use request cache
{ useCache: true } // Use request cache
)
.then(
response => BbPromise.resolve(response.Parameter.Value),
Expand Down
32 changes: 8 additions & 24 deletions lib/classes/Variables.test.js
Expand Up @@ -1318,9 +1318,7 @@ module.exports = {
{
StackName: 'some-stack',
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
})
.finally(() => serverless.getProvider('aws').request.restore());
Expand Down Expand Up @@ -1357,9 +1355,7 @@ module.exports = {
{
StackName: 'some-stack',
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
expect(error).to.be.an.instanceof(Error);
expect(error.message).to.match(/to request a non exported variable from CloudFormation/);
Expand Down Expand Up @@ -1399,9 +1395,7 @@ module.exports = {
Bucket: 'some.bucket',
Key: 'path/to/key',
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
})
.finally(() => serverless.getProvider('aws').request.restore());
Expand Down Expand Up @@ -1452,9 +1446,7 @@ module.exports = {
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
});
});
Expand All @@ -1479,9 +1471,7 @@ module.exports = {
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
});
});
Expand All @@ -1506,9 +1496,7 @@ module.exports = {
Name: param,
WithDecryption: true,
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
});
});
Expand All @@ -1533,9 +1521,7 @@ module.exports = {
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
});
});
Expand All @@ -1560,9 +1546,7 @@ module.exports = {
Name: param,
WithDecryption: false,
},
serverless.variables.options.stage,
serverless.variables.options.region,
true
{ useCache: true }
);
});
});
Expand Down
8 changes: 2 additions & 6 deletions lib/plugins/aws/deploy/lib/checkForChanges.js
Expand Up @@ -32,9 +32,7 @@ module.exports = {

return this.provider.request('S3',
'listObjectsV2',
params,
this.options.stage,
this.options.region
params
).then((result) => {
if (result && result.Contents && result.Contents.length) {
const objects = result.Contents;
Expand Down Expand Up @@ -66,9 +64,7 @@ module.exports = {
{
Bucket: this.bucketName,
Key: obj.Key,
},
this.options.stage,
this.options.region
}
));

return BbPromise.all(headObjectObjects)
Expand Down
28 changes: 7 additions & 21 deletions lib/plugins/aws/deploy/lib/checkForChanges.test.js
Expand Up @@ -120,9 +120,7 @@ describe('checkForChanges', () => {
{
Bucket: awsDeploy.bucketName,
Prefix: 'serverless/my-service/dev',
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(result).to.deep.equal([]);
});
Expand All @@ -142,9 +140,7 @@ describe('checkForChanges', () => {
{
Bucket: awsDeploy.bucketName,
Prefix: 'serverless/my-service/dev',
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(result).to.deep.equal([]);
});
Expand All @@ -169,9 +165,7 @@ describe('checkForChanges', () => {
{
Bucket: awsDeploy.bucketName,
Prefix: 'serverless/my-service/dev',
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(result).to.deep.equal([
{ Key: `${s3Key}/151224711231-2016-08-18T15:43:00/cloudformation.json` },
Expand Down Expand Up @@ -225,39 +219,31 @@ describe('checkForChanges', () => {
{
Bucket: awsDeploy.bucketName,
Key: `${s3Key}/151224711231-2016-08-18T15:43:00/artifact.zip`,
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(headObjectStub).to.have.been.calledWithExactly(
'S3',
'headObject',
{
Bucket: awsDeploy.bucketName,
Key: `${s3Key}/151224711231-2016-08-18T15:43:00/cloudformation.json`,
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(headObjectStub).to.have.been.calledWithExactly(
'S3',
'headObject',
{
Bucket: awsDeploy.bucketName,
Key: `${s3Key}/141264711231-2016-08-18T15:42:00/artifact.zip`,
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
expect(headObjectStub).to.have.been.calledWithExactly(
'S3',
'headObject',
{
Bucket: awsDeploy.bucketName,
Key: `${s3Key}/141264711231-2016-08-18T15:42:00/cloudformation.json`,
},
awsDeploy.options.stage,
awsDeploy.options.region
}
);
});
});
Expand Down
8 changes: 2 additions & 6 deletions lib/plugins/aws/deploy/lib/cleanupS3Bucket.js
Expand Up @@ -16,9 +16,7 @@ module.exports = {
{
Bucket: this.bucketName,
Prefix: `serverless/${service}/${stage}`,
},
this.options.stage,
this.options.region)
})
.then((response) => {
const stacks = findAndGroupDeployments(response, service, stage);
const stacksToKeep = _.takeRight(stacks, stacksToKeepCount);
Expand All @@ -42,9 +40,7 @@ module.exports = {
{
Bucket: this.bucketName,
Delete: { Objects: objectsToRemove },
},
this.options.stage,
this.options.region);
});
}

return BbPromise.resolve();
Expand Down
57 changes: 27 additions & 30 deletions lib/plugins/aws/deploy/lib/cleanupS3Bucket.test.js
@@ -1,11 +1,18 @@
'use strict';

/* eslint-disable no-unused-expressions */

const sinon = require('sinon');
const expect = require('chai').expect;
const chai = require('chai');
const AwsProvider = require('../../provider/awsProvider');
const AwsDeploy = require('../index');
const Serverless = require('../../../../Serverless');

chai.use(require('chai-as-promised'));
chai.use(require('sinon-chai'));

const expect = chai.expect;

describe('cleanupS3Bucket', () => {
let serverless;
let awsDeploy;
Expand Down Expand Up @@ -36,17 +43,15 @@ describe('cleanupS3Bucket', () => {
.stub(awsDeploy.provider, 'request').resolves(serviceObjects);

return awsDeploy.getObjectsToRemove().then(() => {
expect(listObjectsStub.calledOnce).to.be.equal(true);
expect(listObjectsStub.calledWithExactly(
expect(listObjectsStub).to.have.been.calledOnce;
expect(listObjectsStub).to.have.been.calledWithExactly(
'S3',
'listObjectsV2',
{
Bucket: awsDeploy.bucketName,
Prefix: `${s3Key}`,
},
awsDeploy.options.stage,
awsDeploy.options.region
)).to.be.equal(true);
}
);
awsDeploy.provider.request.restore();
});
});
Expand Down Expand Up @@ -98,16 +103,14 @@ describe('cleanupS3Bucket', () => {
.include(
{ Key: `${s3Key}${s3Key}/903940390431-2016-08-18T23:42:08/cloudformation.json` });
expect(listObjectsStub.calledOnce).to.be.equal(true);
expect(listObjectsStub.calledWithExactly(
expect(listObjectsStub).to.have.been.calledWithExactly(
'S3',
'listObjectsV2',
{
Bucket: awsDeploy.bucketName,
Prefix: `${s3Key}`,
},
awsDeploy.options.stage,
awsDeploy.options.region
)).to.be.equal(true);
}
);
awsDeploy.provider.request.restore();
});
});
Expand All @@ -130,16 +133,14 @@ describe('cleanupS3Bucket', () => {
return awsDeploy.getObjectsToRemove().then((objectsToRemove) => {
expect(objectsToRemove.length).to.equal(0);
expect(listObjectsStub.calledOnce).to.be.equal(true);
expect(listObjectsStub.calledWithExactly(
expect(listObjectsStub).to.have.been.calledWithExactly(
'S3',
'listObjectsV2',
{
Bucket: awsDeploy.bucketName,
Prefix: `${s3Key}`,
},
awsDeploy.options.stage,
awsDeploy.options.region
)).to.be.equal(true);
}
);
awsDeploy.provider.request.restore();
});
});
Expand All @@ -162,18 +163,16 @@ describe('cleanupS3Bucket', () => {
.stub(awsDeploy.provider, 'request').resolves(serviceObjects);

return awsDeploy.getObjectsToRemove().then((objectsToRemove) => {
expect(objectsToRemove.length).to.equal(0);
expect(listObjectsStub.calledOnce).to.be.equal(true);
expect(listObjectsStub.calledWithExactly(
expect(objectsToRemove).to.have.lengthOf(0);
expect(listObjectsStub).to.have.been.calledOnce;
expect(listObjectsStub).to.have.been.calledWithExactly(
'S3',
'listObjectsV2',
{
Bucket: awsDeploy.bucketName,
Prefix: `${s3Key}`,
},
awsDeploy.options.stage,
awsDeploy.options.region
)).to.be.equal(true);
}
);
awsDeploy.provider.request.restore();
});
});
Expand Down Expand Up @@ -203,19 +202,17 @@ describe('cleanupS3Bucket', () => {
];

return awsDeploy.removeObjects(objectsToRemove).then(() => {
expect(deleteObjectsStub.calledOnce).to.be.equal(true);
expect(deleteObjectsStub.calledWithExactly(
expect(deleteObjectsStub).to.have.been.calledOnce;
expect(deleteObjectsStub).to.have.been.calledWithExactly(
'S3',
'deleteObjects',
{
Bucket: awsDeploy.bucketName,
Delete: {
Objects: objectsToRemove,
},
},
awsDeploy.options.stage,
awsDeploy.options.region
)).to.be.equal(true);
}
);
awsDeploy.provider.request.restore();
});
});
Expand Down

0 comments on commit 1fb90f6

Please sign in to comment.