Skip to content

Commit 1b839a2

Browse files
committed
add unit test for lambda function from file path
1 parent 21a3141 commit 1b839a2

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/rest-api-construct/src/construct.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ import { App, Stack } from 'aws-cdk-lib';
44
import { Template } from 'aws-cdk-lib/assertions';
55
import * as lambda from 'aws-cdk-lib/aws-lambda';
66

7+
void describe('RestApiConstruct', () => {
8+
void it('loads a function if the folder is specified', () => {
9+
const app = new App();
10+
const stack = new Stack(app);
11+
new RestApiConstruct(stack, 'RestApiLambdaTest', {
12+
apiName: 'RestApiLambdaTest',
13+
apiProps: [
14+
{
15+
path: 'items',
16+
routes: ['GET'],
17+
lambdaEntry: {
18+
runtime: lambda.Runtime.NODEJS_18_X,
19+
source: { path: 'packages/rest-api-construct/lib/test-assets' },
20+
},
21+
},
22+
],
23+
});
24+
const template = Template.fromStack(stack);
25+
template.hasResourceProperties('AWS::Lambda::Function', {
26+
Handler: 'index.handler',
27+
});
28+
});
29+
});
30+
731
void describe('RestApiConstruct', () => {
832
void it('creates a queue if specified', () => {
933
const app = new App();

packages/rest-api-construct/src/construct.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export class RestApiConstruct extends Construct {
3030
const source = lambdaEntry.source;
3131

3232
// Determine Lambda code source - either ExistingDirectory, NewFromCode, or ExistingLambda (function already exists in aws and does not need to be constructed)
33-
let code: lambda.AssetCode | lambda.InlineCode =
34-
lambda.Code.fromInline('');
33+
let code!: lambda.AssetCode | lambda.InlineCode;
3534
if ('path' in source) {
3635
const src = source as ExistingDirectory;
3736
code = lambda.Code.fromAsset(src.path);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Hello world lambda used for testing providing a file for lambda for a rest api path
3+
*/
4+
export const handler = () => {
5+
return 'Hello World! This is a lambda function.';
6+
};

0 commit comments

Comments
 (0)