Refactor functionName retrieval for deployFunction plugin

This commit is contained in:
Philipp Muens 2016-08-08 09:10:22 +02:00
parent 9ba70259b6
commit 78bb9b4173
2 changed files with 7 additions and 9 deletions

View File

@ -15,9 +15,6 @@ class AwsDeployFunction {
this.provider = 'aws';
this.sdk = new SDK(serverless);
this.functionName =
`${this.serverless.service.service}-${this.options.stage}-${this.options.function}`;
this.pkg = new Package(this.serverless, this.options);
Object.assign(this, validate);
@ -34,11 +31,11 @@ class AwsDeployFunction {
checkIfFunctionExists() {
// check if the function exists in the service
this.serverless.service.getFunction(this.options.function);
this.options.functionObj = this.serverless.service.getFunction(this.options.function);
// check if function exists on AWS
const params = {
FunctionName: this.functionName,
FunctionName: this.options.functionObj.name,
};
this.sdk.request(
@ -68,7 +65,7 @@ class AwsDeployFunction {
const data = fs.readFileSync(this.serverless.service.package.artifact);
const params = {
FunctionName: this.functionName,
FunctionName: this.options.functionObj.name,
ZipFile: data,
};

View File

@ -39,6 +39,9 @@ describe('AwsDeployFunction', () => {
stage: 'dev',
region: 'us-east-1',
function: 'first',
functionObj: {
name: 'first',
},
};
serverless.init();
awsDeployFunction = new AwsDeployFunction(serverless, options);
@ -87,9 +90,9 @@ describe('AwsDeployFunction', () => {
const getFunctionStub = sinon
.stub(awsDeployFunction.sdk, 'request').returns(BbPromise.resolve());
awsDeployFunction.functionName = 'first';
awsDeployFunction.serverless.service.functions = {
first: {
name: 'first',
handler: 'handler.first',
},
};
@ -135,8 +138,6 @@ describe('AwsDeployFunction', () => {
const updateFunctionCodeStub = sinon
.stub(awsDeployFunction.sdk, 'request').returns(BbPromise.resolve());
awsDeployFunction.functionName = 'first';
return awsDeployFunction.deployFunction().then(() => {
const data = fs.readFileSync(artifactFilePath);