Skip to content

Commit

Permalink
chore: replace Node16 runtimes in unit tests with symbolic runtime (#…
Browse files Browse the repository at this point in the history
…27011)

To lower the effort for our next hunt-and-peck Node upgrade, replace all runtimes in unit tests with symbolic Node versions.

* Most of the time, use `NODEJS_LATEST`
* Replace expectations of a rendered runtime `"nodejs16.x" -> Runtime.NODEJS_LATEST.name`
* For tests where the hash matters, use a hardcoded fake runtime of `"node99.x"`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Sep 6, 2023
1 parent 49e5739 commit 66a024f
Show file tree
Hide file tree
Showing 59 changed files with 409 additions and 383 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Match, Template } from 'aws-cdk-lib/assertions';
import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Function } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Duration, Stack } from 'aws-cdk-lib';
import { DummyRouteIntegration } from './integration';
import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib';
Expand All @@ -13,7 +14,7 @@ describe('HttpLambdaAuthorizer', () => {
const api = new HttpApi(stack, 'HttpApi');

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('HttpLambdaAuthorizer', () => {
const api = new HttpApi(stack, 'HttpApi');

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('HttpLambdaAuthorizer', () => {
const api = new HttpApi(stack, 'HttpApi');

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -107,7 +108,7 @@ describe('HttpLambdaAuthorizer', () => {
const api = new HttpApi(stack, 'HttpApi');

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -136,7 +137,7 @@ describe('HttpLambdaAuthorizer', () => {
const api = new HttpApi(stack, 'HttpApi');

const handler = new Function(stack, 'auth-functon', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Template } from 'aws-cdk-lib/assertions';
import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha';
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Function } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Stack } from 'aws-cdk-lib';
import { WebSocketIamAuthorizer } from '../../lib';

Expand All @@ -10,7 +11,7 @@ describe('WebSocketLambdaAuthorizer', () => {
const stack = new Stack();

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Template } from 'aws-cdk-lib/assertions';
import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha';
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Function } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Stack } from 'aws-cdk-lib';
import { WebSocketLambdaAuthorizer } from '../../lib';

Expand All @@ -11,7 +12,7 @@ describe('WebSocketLambdaAuthorizer', () => {
const stack = new Stack();

const handler = new Function(stack, 'auth-function', {
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: Code.fromInline('exports.handler = () => {return true}'),
handler: 'index.handler',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Match, Template } from 'aws-cdk-lib/assertions';
import { HttpApi, HttpRoute, HttpRouteKey, MappingValue, ParameterMapping, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2-alpha';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Function } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { App, Stack } from 'aws-cdk-lib';
import { HttpLambdaIntegration } from '../../lib';

Expand Down Expand Up @@ -111,7 +112,7 @@ describe('LambdaProxyIntegration', () => {
function fooFunction(stack: Stack, id: string) {
return new Function(stack, id, {
code: Code.fromInline('foo'),
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Template } from 'aws-cdk-lib/assertions';
import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Function } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Stack } from 'aws-cdk-lib';
import { WebSocketLambdaIntegration } from '../../lib';

Expand Down Expand Up @@ -50,7 +51,7 @@ describe('LambdaWebSocketIntegration', () => {
function fooFunction(stack: Stack, id: string) {
return new Function(stack, id, {
code: Code.fromInline('foo'),
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('create a topic rule with lambda action and a lambda permission to be invok
sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"),
});
const func = new lambda.Function(stack, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('console.log("foo")'),
});
Expand Down Expand Up @@ -60,7 +60,7 @@ test('create two different permissions, when two topic rules have the same actio
// GIVEN
const stack = new cdk.Stack();
const func = new lambda.Function(stack, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('console.log("foo")'),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('S3 destination', () => {

beforeEach(() => {
lambdaFunction = new lambda.Function(stack, 'DataProcessorFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('foo'),
handler: 'bar',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import { Template } from 'aws-cdk-lib/assertions';
import { Code, Runtime } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib';
import { PythonFunction } from '../lib';
import { Bundling, BundlingProps } from '../lib/bundling';
Expand Down Expand Up @@ -112,7 +113,7 @@ test('throws when entry does not exist', () => {
test('throws with the wrong runtime family', () => {
expect(() => new PythonFunction(stack, 'handler1', {
entry: path.join(__dirname, 'lambda-handler'),
runtime: Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
})).toThrow(/Only `PYTHON` runtimes are supported/);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ beforeEach(() => {
stack = new cdk.Stack();
bucket = new s3.Bucket(stack, 'MyBucket');
handler = new lambda.Function(stack, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.hello',
code: new lambda.InlineCode('def hello(): pass'),
});
Expand Down
20 changes: 10 additions & 10 deletions packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const auth = new TokenAuthorizer(stack, 'myauthorizer', {
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const auth = new RequestAuthorizer(stack, 'myauthorizer', {
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

expect(() => new RequestAuthorizer(stack, 'myauthorizer', {
Expand All @@ -175,7 +175,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const auth = new TokenAuthorizer(stack, 'myauthorizer', {
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const auth = new RequestAuthorizer(stack, 'myauthorizer', {
Expand Down Expand Up @@ -319,7 +319,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const role = new iam.Role(stack, 'authorizerassumerole', {
Expand Down Expand Up @@ -409,7 +409,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const role = new iam.Role(stack, 'authorizerassumerole', {
Expand Down Expand Up @@ -500,7 +500,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});
const auth = new TokenAuthorizer(stack, 'myauthorizer', {
handler: func,
Expand All @@ -514,7 +514,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});
const auth = new RequestAuthorizer(stack, 'myauthorizer', {
handler: func,
Expand Down Expand Up @@ -559,7 +559,7 @@ describe('lambda authorizer', () => {
const func = new lambda.Function(stack, 'myfunction', {
handler: 'handler',
code: lambda.Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

const auth = new RequestAuthorizer(stack, 'myauthorizer', {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ describe('cors', () => {
const handler = new lambda.Function(stack, 'handler', {
handler: 'index.handler',
code: lambda.Code.fromInline('boom'),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
});

// WHEN
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ describe('deployment', () => {
const stack2 = new Stack();
const handler1 = new lambda.Function(stack1, 'handler1', {
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});
const handler2 = new lambda.Function(stack2, 'handler2', {
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('lambda', () => {
// GIVEN
const stack = new cdk.Stack();
const fn = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('lambda', () => {
// GIVEN
const stack = new cdk.Stack();
const fn = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
});
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('lambda', () => {
// GIVEN
const stack = new cdk.Stack();
const fn = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
});
Expand All @@ -162,7 +162,7 @@ describe('lambda', () => {
const api = new apigateway.RestApi(stack, 'test-api');

const handler = new lambda.Function(stack, 'MyFunc', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('loo'),
});
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('lambda', () => {
});

const handler = new lambda.Function(stack, 'MyFunc', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('loo'),
});
Expand All @@ -249,7 +249,7 @@ describe('lambda', () => {
const method = restapi.root.addMethod('ANY');
const handler = new lambda.Function(stack, 'MyFunc', {
functionName: 'ThisFunction',
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('loo'),
});
Expand All @@ -269,7 +269,7 @@ describe('lambda', () => {
const restapi = new apigateway.RestApi(stack, 'RestApi');
const method = restapi.root.addMethod('ANY');
const handler = new lambda.Function(stack, 'MyFunc', {
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('loo'),
});
Expand Down
Loading

0 comments on commit 66a024f

Please sign in to comment.