Skip to content

Commit

Permalink
feat: testing L2 constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevinwochan committed Jun 17, 2024
1 parent 71793d0 commit bc1d61c
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions test/rules/Lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
Function,
FunctionUrlAuthType,
Runtime,
LogFormat,
SystemLogLevel,
ApplicationLogLevel,
} from 'aws-cdk-lib/aws-lambda';
import { LogGroup } from 'aws-cdk-lib/aws-logs';
import { TestPack, TestType, validateStack } from './utils';
import {
LambdaConcurrency,
Expand Down Expand Up @@ -356,15 +360,27 @@ describe('AWS Lambda', () => {

describe('LambdaLogging: Ensure that Lambda functions have a corresponding Log Group', () => {
const ruleId = 'LambdaLogging';
test('Noncompliance 1', () => {
test('Noncompliance 1 - L1 Construct', () => {
new CfnFunction(stack, 'Function', {
code: {},
role: 'somerole',
});
validateStack(stack, ruleId, TestType.NON_COMPLIANCE);
});

test('Compliance', () => {
test('Noncompliance 2 - L2 Constructs', () => {
new Function(stack, 'Function', {
handler: '',
runtime: Runtime.NODEJS_LATEST,
code: Code.fromInline('console.log("hello world'),
logFormat: LogFormat.JSON,
applicationLogLevel: ApplicationLogLevel.TRACE,
systemLogLevel: SystemLogLevel.WARN
});
validateStack(stack, ruleId, TestType.NON_COMPLIANCE);
});

test('Compliance - L1 Construct', () => {
new CfnFunction(stack, 'Function', {
code: {},
role: 'somerole',
Expand All @@ -377,5 +393,18 @@ describe('AWS Lambda', () => {
});
validateStack(stack, ruleId, TestType.COMPLIANCE);
});

test('Compliance 1 - L2 Constructs', () => {
new Function(stack, 'Function', {
handler: '',
runtime: Runtime.NODEJS_LATEST,
code: Code.fromInline('console.log("hello world'),
logFormat: LogFormat.JSON,
applicationLogLevel: ApplicationLogLevel.TRACE,
systemLogLevel: SystemLogLevel.WARN,
logGroup: new LogGroup(stack, 'LogGroup'),
});
validateStack(stack, ruleId, TestType.COMPLIANCE);
});
});
});

0 comments on commit bc1d61c

Please sign in to comment.