From 9d7b4d26ac5d18749aba690104d44e8dae2b6aec Mon Sep 17 00:00:00 2001 From: Jordan Storms Date: Tue, 26 Oct 2021 14:13:08 -0400 Subject: [PATCH] fix tests --- packages/@aws-cdk/aws-lambda/lib/function.ts | 6 ++-- .../@aws-cdk/aws-lambda/test/function.test.ts | 29 +++++++++++++++++-- .../aws-lambda/test/lambda-insights.test.ts | 4 ++- .../aws-lambda/test/singleton-lambda.test.ts | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/function.ts b/packages/@aws-cdk/aws-lambda/lib/function.ts index 9489c76e966dd..631002a8fbf83 100644 --- a/packages/@aws-cdk/aws-lambda/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda/lib/function.ts @@ -576,7 +576,7 @@ export class Function extends FunctionBase { /** * The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64). */ - public readonly architecture: Architecture; + public readonly architecture?: Architecture; public readonly permissionsNode = this.node; @@ -677,7 +677,7 @@ export class Function extends FunctionBase { if (props.architectures && props.architectures.length > 1) { throw new Error('Only one architecture must be specified.'); } - const architecture = props.architecture ?? (props.architectures && props.architectures[0]); + const architecture = props.architecture ?? (props.architectures && props.architectures[0]) ?? Architecture.X86_64; const resource: CfnFunction = new CfnFunction(this, 'Resource', { functionName: this.physicalName, @@ -726,7 +726,7 @@ export class Function extends FunctionBase { this.runtime = props.runtime; - this.architecture = props.architecture; + this.architecture = architecture; if (props.layers) { if (props.runtime === Runtime.FROM_IMAGE) { diff --git a/packages/@aws-cdk/aws-lambda/test/function.test.ts b/packages/@aws-cdk/aws-lambda/test/function.test.ts index 845b2ae8ad099..fc20c1783b893 100644 --- a/packages/@aws-cdk/aws-lambda/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/function.test.ts @@ -44,6 +44,9 @@ describe('function', () => { Properties: { Code: { ZipFile: 'foo' }, + Architectures: [ + 'x86_64', + ], Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, Runtime: 'nodejs10.x', @@ -97,6 +100,7 @@ describe('function', () => { expect(stack).toHaveResource('AWS::Lambda::Function', { Properties: { Code: { ZipFile: 'foo' }, + Architectures: ['x86_64'], Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, Runtime: 'nodejs10.x', @@ -149,6 +153,9 @@ describe('function', () => { Code: { ZipFile: 'foo', }, + Architectures: [ + 'x86_64', + ], Handler: 'bar', Role: { 'Fn::GetAtt': [ @@ -393,6 +400,9 @@ describe('function', () => { ]], }, }, + Architectures: [ + 'x86_64', + ], Handler: 'index.handler', Role: { 'Fn::GetAtt': [ @@ -471,6 +481,9 @@ describe('function', () => { Code: { ZipFile: 'foo', }, + Architectures: [ + 'x86_64', + ], Handler: 'index.handler', Role: { 'Fn::GetAtt': [ @@ -536,6 +549,9 @@ describe('function', () => { Code: { ZipFile: 'foo', }, + Architectures: [ + 'x86_64', + ], Handler: 'index.handler', Role: { 'Fn::GetAtt': [ @@ -699,6 +715,9 @@ describe('function', () => { 'Arn', ], }, + Architectures: [ + 'x86_64', + ], Runtime: 'nodejs10.x', TracingConfig: { Mode: 'Active', @@ -748,6 +767,9 @@ describe('function', () => { Code: { ZipFile: 'foo', }, + Architectures: [ + 'x86_64', + ], Handler: 'index.handler', Role: { 'Fn::GetAtt': [ @@ -811,6 +833,9 @@ describe('function', () => { 'Arn', ], }, + Architectures: [ + 'x86_64', + ], Runtime: 'nodejs10.x', }, DependsOn: [ @@ -2234,7 +2259,7 @@ describe('function', () => { handler: 'index.handler', architecture: lambda.Architecture.ARM_64, }); - expect(fn.architecture.name).toEqual('arm64'); + expect(fn.architecture?.name).toEqual('arm64'); }); test('Architecture returns amd64 when no architecture is set', () => { const stack = new cdk.Stack(); @@ -2243,7 +2268,7 @@ describe('function', () => { runtime: lambda.Runtime.NODEJS_14_X, handler: 'index.handler', }); - expect(fn.architecture.name).toEqual('amd64'); + expect(fn.architecture?.name).toEqual('x86_64'); }); }); diff --git a/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts b/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts index 762df158da6f4..12e93e7ad87b3 100644 --- a/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts @@ -166,6 +166,7 @@ describe('lambda-insights', () => { 'Arn', ], }, + 'Architectures': ['x86_64'], 'Handler': 'index.handler', 'Layers': [ { @@ -239,6 +240,7 @@ describe('lambda-insights', () => { 'Arn', ], }, + 'Architectures': ['x86_64'], 'Handler': 'index.handler', 'Layers': [ { @@ -337,7 +339,7 @@ describe('lambda-insights', () => { ], }, 'ManagedPolicyArns': [ - { }, + {}, { 'Fn::Join': [ '', diff --git a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts index 3bf78253d5ed6..08adc878d895a 100644 --- a/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts @@ -52,6 +52,7 @@ describe('singleton lambda', () => { }, Handler: 'index.hello', Role: { 'Fn::GetAtt': ['SingletonLambda84c0de93353f42179b0b45b6c993251aServiceRole26D59235', 'Arn'] }, + Architectures: ['x86_64'], Runtime: 'python2.7', Timeout: 300, },