From ecc172c2a6af2c4d211df34d619a4eb215b2e374 Mon Sep 17 00:00:00 2001 From: ozwi Date: Thu, 10 Sep 2020 10:50:25 +0300 Subject: [PATCH 01/11] exclude tags and reservedConcurrency from version hash --- .../aws/package/compile/functions/index.js | 3 +- .../package/compile/functions/index.test.js | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index dcebf88cf9b..b54d5b4d703 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -494,7 +494,8 @@ class AwsCompileFunctions { }); }).then(() => { // Include function configuration in version id hash (without the Code part) - const properties = _.omit(_.get(functionResource, 'Properties', {}), 'Code'); + const functionWideProperties = ['ReservedConcurrentExecutions', 'Tags']; + const properties = _.omit(_.get(functionResource, 'Properties', {}), 'Code', ...functionWideProperties); _.forOwn(properties, value => { if (_.isObject(value)) { versionHash.write(JSON.stringify(value)); diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 33a1bad5d3e..0964d929f03 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2240,6 +2240,63 @@ describe('AwsCompileFunctions', () => { }); }); + it('should not create a new version object if only function-wide configuration changed', () => { + awsCompileFunctions.serverless.service.functions = { + func: { + handler: 'func.function.handler', + }, + anotherFunc: { + handler: 'anotherFunc.function.handler', + }, + }; + + const expectedOutputs = { + FuncLambdaFunctionQualifiedArn: { + Description: 'Current Lambda function version', + Value: { Ref: 'FuncLambdaVersionRk2uCHjn9BWyD0yH8GzU5kTmGVjCc6ZZx46sUUI1LQ' }, + }, + AnotherFuncLambdaFunctionQualifiedArn: { + Description: 'Current Lambda function version', + Value: { + Ref: 'AnotherFuncLambdaVersionha2TZXucQgvNN4zjzNnEFIaTGAQxdp7jICMvFkl0', + }, + }, + }; + + return expect(awsCompileFunctions.compileFunctions()) + .to.be.fulfilled.then(() => { + expect( + awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Outputs + ).to.deep.equal(expectedOutputs); + + // Change configuration + awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate = { + Resources: {}, + Outputs: {}, + }; + + _.set( + awsCompileFunctions, + 'serverless.service.functions.func.tags', + {MYTAG: 'mytag'} + ); + + _.set( + awsCompileFunctions, + 'serverless.service.functions.func.reservedConcurrency', + 1 + ); + + return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled; + }) + .then(() => { + // Expect same version hash + expect( + awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Outputs + ).to.deep.equal(expectedOutputs); + }); + }); + it('should include description under version too if function is specified', () => { awsCompileFunctions.serverless.service.functions = { func: { From c1adb6a5af29ba63ec2d3749ac2bbc220fc8dd34 Mon Sep 17 00:00:00 2001 From: ozwi Date: Thu, 10 Sep 2020 11:18:16 +0300 Subject: [PATCH 02/11] push prettify changes --- lib/plugins/aws/package/compile/functions/index.js | 6 +++++- .../aws/package/compile/functions/index.test.js | 12 ++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index b54d5b4d703..977e1bf772e 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -495,7 +495,11 @@ class AwsCompileFunctions { }).then(() => { // Include function configuration in version id hash (without the Code part) const functionWideProperties = ['ReservedConcurrentExecutions', 'Tags']; - const properties = _.omit(_.get(functionResource, 'Properties', {}), 'Code', ...functionWideProperties); + const properties = _.omit( + _.get(functionResource, 'Properties', {}), + 'Code', + ...functionWideProperties + ); _.forOwn(properties, value => { if (_.isObject(value)) { versionHash.write(JSON.stringify(value)); diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 0964d929f03..8dd23beafc2 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2275,17 +2275,9 @@ describe('AwsCompileFunctions', () => { Outputs: {}, }; - _.set( - awsCompileFunctions, - 'serverless.service.functions.func.tags', - {MYTAG: 'mytag'} - ); + _.set(awsCompileFunctions, 'serverless.service.functions.func.tags', { MYTAG: 'mytag' }); - _.set( - awsCompileFunctions, - 'serverless.service.functions.func.reservedConcurrency', - 1 - ); + _.set(awsCompileFunctions, 'serverless.service.functions.func.reservedConcurrency', 1); return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled; }) From 8562f4f598675a2791fd444e5db8dbbdbd680227 Mon Sep 17 00:00:00 2001 From: ozwi Date: Fri, 11 Sep 2020 12:21:52 +0300 Subject: [PATCH 03/11] refactor test - use runServerless --- .../package/compile/functions/index.test.js | 81 ++++++++----------- 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 8dd23beafc2..41a20be7094 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -10,6 +10,7 @@ const AwsProvider = require('../../../provider/awsProvider'); const AwsCompileFunctions = require('./index'); const Serverless = require('../../../../../Serverless'); const runServerless = require('../../../../../../test/utils/run-serverless'); +const fixtures = require('../../../../../../test/fixtures'); const { getTmpDirPath, createTmpFile } = require('../../../../../../test/utils/fs'); @@ -2240,55 +2241,6 @@ describe('AwsCompileFunctions', () => { }); }); - it('should not create a new version object if only function-wide configuration changed', () => { - awsCompileFunctions.serverless.service.functions = { - func: { - handler: 'func.function.handler', - }, - anotherFunc: { - handler: 'anotherFunc.function.handler', - }, - }; - - const expectedOutputs = { - FuncLambdaFunctionQualifiedArn: { - Description: 'Current Lambda function version', - Value: { Ref: 'FuncLambdaVersionRk2uCHjn9BWyD0yH8GzU5kTmGVjCc6ZZx46sUUI1LQ' }, - }, - AnotherFuncLambdaFunctionQualifiedArn: { - Description: 'Current Lambda function version', - Value: { - Ref: 'AnotherFuncLambdaVersionha2TZXucQgvNN4zjzNnEFIaTGAQxdp7jICMvFkl0', - }, - }, - }; - - return expect(awsCompileFunctions.compileFunctions()) - .to.be.fulfilled.then(() => { - expect( - awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Outputs - ).to.deep.equal(expectedOutputs); - - // Change configuration - awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate = { - Resources: {}, - Outputs: {}, - }; - - _.set(awsCompileFunctions, 'serverless.service.functions.func.tags', { MYTAG: 'mytag' }); - - _.set(awsCompileFunctions, 'serverless.service.functions.func.reservedConcurrency', 1); - - return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled; - }) - .then(() => { - // Expect same version hash - expect( - awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Outputs - ).to.deep.equal(expectedOutputs); - }); - }); - it('should include description under version too if function is specified', () => { awsCompileFunctions.serverless.service.functions = { func: { @@ -2964,4 +2916,35 @@ describe('AwsCompileFunctions #2', () => { }); }); }); + + describe('function config', () => { + it.only('should not create a new version object if only function-wide configuration changed', () => { + return fixtures.setup('function').then(({ servicePath, updateConfig }) => + runServerless({ + cwd: servicePath, + cliArgs: ['package'], + }).then(({ cfTemplate: originalTemplate }) => { + const originalVersionArn = originalTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref + return updateConfig({ + functions: { + foo: { + tags: { + foo: 'bar' + }, + reservedConcurrency: 1 + } + }, + }).then(() => + runServerless({ + cwd: servicePath, + cliArgs: ['package'], + }).then(({ cfTemplate: updatedTemplate }) => { + expect(updatedTemplate.Resources.FooLambdaFunction.Properties.ReservedConcurrentExecutions).to.equal(1); + const updatedVersionArn = updatedTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref + expect(originalVersionArn).to.equal(updatedVersionArn); + }) + ); + })); + }); + }); }); From 19ab38cb06d33f6f0c9ed9c922983cb16bc40dd5 Mon Sep 17 00:00:00 2001 From: ozwi Date: Fri, 11 Sep 2020 12:29:55 +0300 Subject: [PATCH 04/11] replace variable with comment --- lib/plugins/aws/package/compile/functions/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index 977e1bf772e..64ff80d63bd 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -494,11 +494,12 @@ class AwsCompileFunctions { }); }).then(() => { // Include function configuration in version id hash (without the Code part) - const functionWideProperties = ['ReservedConcurrentExecutions', 'Tags']; const properties = _.omit( _.get(functionResource, 'Properties', {}), 'Code', - ...functionWideProperties + // exclude function-wide properties: https://github.com/serverless/serverless/issues/7822 + 'ReservedConcurrentExecutions', + 'Tags' ); _.forOwn(properties, value => { if (_.isObject(value)) { From 6efc191a2be878f867c8f0bea854642e39c22d45 Mon Sep 17 00:00:00 2001 From: ozwi Date: Fri, 11 Sep 2020 12:32:16 +0300 Subject: [PATCH 05/11] better comment --- lib/plugins/aws/package/compile/functions/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index 64ff80d63bd..cf629e7848e 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -497,7 +497,8 @@ class AwsCompileFunctions { const properties = _.omit( _.get(functionResource, 'Properties', {}), 'Code', - // exclude function-wide properties: https://github.com/serverless/serverless/issues/7822 + // Properties applied to function globally (not specific to version or alias) + // https://github.com/serverless/serverless/issues/7822 'ReservedConcurrentExecutions', 'Tags' ); From b424b3c4a28df052efeb7f004e2402d877ff885a Mon Sep 17 00:00:00 2001 From: ozwi Date: Mon, 14 Sep 2020 15:50:58 +0300 Subject: [PATCH 06/11] remove pr link --- lib/plugins/aws/package/compile/functions/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index 5bdd4348c23..7d8f6450549 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -498,7 +498,6 @@ class AwsCompileFunctions { _.get(functionResource, 'Properties', {}), 'Code', // Properties applied to function globally (not specific to version or alias) - // https://github.com/serverless/serverless/issues/7822 'ReservedConcurrentExecutions', 'Tags' ); From 613e737c8b0609faaebc28e3900ae223299983d8 Mon Sep 17 00:00:00 2001 From: ozwi Date: Mon, 14 Sep 2020 15:52:00 +0300 Subject: [PATCH 07/11] prettify --- .../package/compile/functions/index.test.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 1ca589ba299..8620e3cf288 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2840,27 +2840,32 @@ describe('AwsCompileFunctions #2', () => { cwd: servicePath, cliArgs: ['package'], }).then(({ cfTemplate: originalTemplate }) => { - const originalVersionArn = originalTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref + const originalVersionArn = + originalTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; return updateConfig({ functions: { foo: { tags: { - foo: 'bar' + foo: 'bar', }, - reservedConcurrency: 1 - } + reservedConcurrency: 1, + }, }, }).then(() => runServerless({ cwd: servicePath, cliArgs: ['package'], }).then(({ cfTemplate: updatedTemplate }) => { - expect(updatedTemplate.Resources.FooLambdaFunction.Properties.ReservedConcurrentExecutions).to.equal(1); - const updatedVersionArn = updatedTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref + expect( + updatedTemplate.Resources.FooLambdaFunction.Properties.ReservedConcurrentExecutions + ).to.equal(1); + const updatedVersionArn = + updatedTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; expect(originalVersionArn).to.equal(updatedVersionArn); }) ); - })); + }) + ); }); }); }); From 16be040212a844fe26ff8abdbb1aced3ea163fb9 Mon Sep 17 00:00:00 2001 From: ozwi Date: Mon, 14 Sep 2020 15:53:22 +0300 Subject: [PATCH 08/11] revert .only --- lib/plugins/aws/package/compile/functions/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 8620e3cf288..65c771b083f 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2834,7 +2834,7 @@ describe('AwsCompileFunctions #2', () => { }); describe('function config', () => { - it.only('should not create a new version object if only function-wide configuration changed', () => { + it('should not create a new version object if only function-wide configuration changed', () => { return fixtures.setup('function').then(({ servicePath, updateConfig }) => runServerless({ cwd: servicePath, From b8dee0e9ed99142656b8965b1c09af1daae9975b Mon Sep 17 00:00:00 2001 From: ozwi Date: Tue, 15 Sep 2020 11:46:04 +0300 Subject: [PATCH 09/11] async/await!!! --- .../package/compile/functions/index.test.js | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 65c771b083f..fb74464a206 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2834,38 +2834,36 @@ describe('AwsCompileFunctions #2', () => { }); describe('function config', () => { - it('should not create a new version object if only function-wide configuration changed', () => { - return fixtures.setup('function').then(({ servicePath, updateConfig }) => - runServerless({ - cwd: servicePath, - cliArgs: ['package'], - }).then(({ cfTemplate: originalTemplate }) => { - const originalVersionArn = - originalTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; - return updateConfig({ - functions: { - foo: { - tags: { - foo: 'bar', - }, - reservedConcurrency: 1, - }, + it('should not create a new version object if only function-wide configuration changed', async () => { + const { servicePath, updateConfig } = fixtures.setup('function'); + + const { cfTemplate: originalTemplate } = runServerless({ + cwd: servicePath, + cliArgs: ['package'], + }); + const originalVersionArn = originalTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; + + await updateConfig({ + functions: { + foo: { + tags: { + foo: 'bar', }, - }).then(() => - runServerless({ - cwd: servicePath, - cliArgs: ['package'], - }).then(({ cfTemplate: updatedTemplate }) => { - expect( - updatedTemplate.Resources.FooLambdaFunction.Properties.ReservedConcurrentExecutions - ).to.equal(1); - const updatedVersionArn = - updatedTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; - expect(originalVersionArn).to.equal(updatedVersionArn); - }) - ); - }) - ); + reservedConcurrency: 1, + }, + }, + }); + const { cfTemplate: updatedTemplate } = runServerless({ + cwd: servicePath, + cliArgs: ['package'], + }); + const updatedVersionArn = updatedTemplate.Outputs.FooLambdaFunctionQualifiedArn.Value.Ref; + + expect( + updatedTemplate.Resources.FooLambdaFunction.Properties.ReservedConcurrentExecutions + ).to.equal(1); + + expect(originalVersionArn).to.equal(updatedVersionArn); }); }); }); From 39e31eb4ee6383997781fb9a0f1fe0fffc2d6635 Mon Sep 17 00:00:00 2001 From: ozwi Date: Tue, 15 Sep 2020 11:48:09 +0300 Subject: [PATCH 10/11] async/await!!! - for real --- lib/plugins/aws/package/compile/functions/index.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index fb74464a206..3b2078fb4ef 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2833,11 +2833,11 @@ describe('AwsCompileFunctions #2', () => { }); }); - describe('function config', () => { + describe.only('function config', () => { it('should not create a new version object if only function-wide configuration changed', async () => { - const { servicePath, updateConfig } = fixtures.setup('function'); + const { servicePath, updateConfig } = await fixtures.setup('function'); - const { cfTemplate: originalTemplate } = runServerless({ + const { cfTemplate: originalTemplate } = await runServerless({ cwd: servicePath, cliArgs: ['package'], }); @@ -2853,7 +2853,7 @@ describe('AwsCompileFunctions #2', () => { }, }, }); - const { cfTemplate: updatedTemplate } = runServerless({ + const { cfTemplate: updatedTemplate } = await runServerless({ cwd: servicePath, cliArgs: ['package'], }); From e29da470b8d1c123e51776a27c6b57e659220ef8 Mon Sep 17 00:00:00 2001 From: Oz Weiss Date: Tue, 22 Sep 2020 10:16:57 +0300 Subject: [PATCH 11/11] remove .only --- lib/plugins/aws/package/compile/functions/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/aws/package/compile/functions/index.test.js b/lib/plugins/aws/package/compile/functions/index.test.js index 3b2078fb4ef..d99d70b80bb 100644 --- a/lib/plugins/aws/package/compile/functions/index.test.js +++ b/lib/plugins/aws/package/compile/functions/index.test.js @@ -2833,7 +2833,7 @@ describe('AwsCompileFunctions #2', () => { }); }); - describe.only('function config', () => { + describe('function config', () => { it('should not create a new version object if only function-wide configuration changed', async () => { const { servicePath, updateConfig } = await fixtures.setup('function');