-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* chore: added integration tests * chore: update dependencies * chore: run projen build * feat: added integration test with integ-runner * chore: self mutation Signed-off-by: github-actions <[email protected]> * test: update integration test * docs: added documentation --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
import { clickupCdk } from '@time-loop/clickup-projen'; | ||
import { JsonPatch } from 'projen'; | ||
|
||
const repoName = 'cdk-lambda-eni-usage-metric-publisher'; | ||
const project = new clickupCdk.ClickUpCdkConstructLibrary({ | ||
author: 'jose-clickup', | ||
authorAddress: '[email protected]', | ||
cdkVersion: '2.99.0', | ||
cdkVersion: '2.105.0', | ||
defaultReleaseBranch: 'main', | ||
devDeps: ['@time-loop/clickup-projen', '@aws-cdk/integ-tests-alpha', 'aws-sdk-mock'], | ||
devDeps: ['@time-loop/clickup-projen', '@aws-cdk/integ-tests-alpha', 'aws-sdk-mock', '@aws-sdk/client-cloudwatch'], | ||
jsiiVersion: '~5.0.0', | ||
name: 'cdk-lambda-eni-usage-metric-publisher', | ||
projenrcTs: true, | ||
repositoryUrl: 'https://github.com/time-loop/cdk-lambda-eni-usage-metric-publisher.git', | ||
gitignore: ['.vscode/**'], | ||
bundledDeps: ['aws-sdk'], | ||
peerDeps: ['multi-convention-namer'], | ||
experimentalIntegRunner: true, | ||
// deps: [] /* Runtime dependencies of this module. */, | ||
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */ | ||
// packageName: undefined, /* The "name" in package.json. */ | ||
}); | ||
// Assume the usInfraDev role | ||
const build = project.tryFindObjectFile('.github/workflows/build.yml'); | ||
build?.addOverride('jobs.build.permissions', { 'id-token': 'write' }); | ||
build?.patch( | ||
JsonPatch.add('/jobs/build/steps/0', { | ||
Check failure on line 27 in .projenrc.ts
|
||
name: 'Configure AWS Credentials', | ||
uses: 'aws-actions/configure-aws-credentials@v2', | ||
with: { | ||
'aws-region': 'us-west-2', | ||
'role-to-assume': `arn:aws:iam::425845004253:role/${repoName}-github-actions-role`, | ||
'role-duration-seconds': 900, | ||
}, | ||
}), | ||
); | ||
project.synth(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"vpc-provider:account=425845004253:filter.vpc-id=vpc-00f8af8d4967b2a3b:region=us-west-2:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-00f8af8d4967b2a3b", | ||
"vpcCidrBlock": "10.60.0.0/16", | ||
"ownerAccountId": "425845004253", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Isolated", | ||
"type": "Isolated", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-02127dec34cbcdf7e", | ||
"cidr": "10.60.1.0/24", | ||
"availabilityZone": "us-west-2a", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
}, | ||
{ | ||
"subnetId": "subnet-0c9e0da263eaaf57f", | ||
"cidr": "10.60.2.0/24", | ||
"availabilityZone": "us-west-2b", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
}, | ||
{ | ||
"subnetId": "subnet-013ad4436277f8fb8", | ||
"cidr": "10.60.3.0/24", | ||
"availabilityZone": "us-west-2c", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"vpc-provider:account=425845004253:filter.vpc-id=vpc-00f8af8d4967b2a3b:region=us-west-2:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-00f8af8d4967b2a3b", | ||
"vpcCidrBlock": "10.60.0.0/16", | ||
"ownerAccountId": "425845004253", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Isolated", | ||
"type": "Isolated", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-02127dec34cbcdf7e", | ||
"cidr": "10.60.1.0/24", | ||
"availabilityZone": "us-west-2a", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
}, | ||
{ | ||
"subnetId": "subnet-0c9e0da263eaaf57f", | ||
"cidr": "10.60.2.0/24", | ||
"availabilityZone": "us-west-2b", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
}, | ||
{ | ||
"subnetId": "subnet-013ad4436277f8fb8", | ||
"cidr": "10.60.3.0/24", | ||
"availabilityZone": "us-west-2c", | ||
"routeTableId": "rtb-0c2aa60a7630b0f63" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { join } from 'path'; | ||
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha'; | ||
import { App, Stack, StackProps, aws_lambda_nodejs, aws_ec2, Duration, aws_iam } from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { Namer } from 'multi-convention-namer'; | ||
import { IntegTestResources } from './utils/integ-tests-types'; | ||
import { LambdaEniUsageMetricPublisher } from '../src'; | ||
// The BaselineStack creates an instance of LambdaEniUsageMetricPublisher | ||
export class BaselineStack extends Stack { | ||
readonly lambdaFunction: LambdaEniUsageMetricPublisher; | ||
|
||
constructor(scope: Construct, props: StackProps) { | ||
const id = new Namer(['monitor', 'baseline']); | ||
super(scope, id.pascal, props); | ||
this.lambdaFunction = new LambdaEniUsageMetricPublisher(this, id, { | ||
publishFrequency: 1, | ||
regions: [IntegTestResources.AWS_REGION], | ||
cwNamespace: 'LambdaHyperplaneEniUsage', | ||
}); | ||
} | ||
} | ||
|
||
// The AssertionStack creates AWS Lambda helpers to run the assertions | ||
export class AssertionStack extends Stack { | ||
constructor(scope: Construct, props: StackProps) { | ||
const id = new Namer(['helper', 'monitor', 'baseline']); | ||
super(scope, id.pascal, props); | ||
// The Lambda DummyFunction cover the scenarios where no Lambda functions are deployed in a VPC. | ||
new aws_lambda_nodejs.NodejsFunction(this, 'DummyFunction', { | ||
vpc: aws_ec2.Vpc.fromLookup(this, 'ImportVPC', { | ||
vpcId: IntegTestResources.VPC_ID, | ||
}), | ||
entry: join(__dirname, 'utils/hello-world.ts'), | ||
allowPublicSubnet: true, | ||
}); | ||
// The Lambda GetEniIntegRunnerFunction is used to run the assertions as the current awsApiCall presents an issue with the AWS SDK and timestamps parsing. | ||
new aws_lambda_nodejs.NodejsFunction(this, 'GetEniIntegRunnerFunction', { | ||
functionName: 'GetEniIntegRunnerFunction', | ||
entry: join(__dirname, 'utils/get-eni-usage-metrics.ts'), | ||
timeout: Duration.seconds(15), | ||
}).addToRolePolicy( | ||
new aws_iam.PolicyStatement({ | ||
actions: ['cloudwatch:GetMetricData'], | ||
resources: ['*'], | ||
}), | ||
); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
const stack = new BaselineStack(app, { | ||
env: { | ||
account: IntegTestResources.AWS_ACCOUNT, | ||
region: IntegTestResources.AWS_REGION, | ||
}, | ||
}); | ||
const assertionStack = new AssertionStack(app, { | ||
env: { | ||
account: IntegTestResources.AWS_ACCOUNT, | ||
region: IntegTestResources.AWS_REGION, | ||
}, | ||
}); | ||
|
||
const integ = new IntegTest(app, 'integ', { | ||
testCases: [stack], | ||
enableLookups: true, | ||
cdkCommandOptions: { | ||
destroy: { | ||
args: { | ||
force: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
integ.node.addDependency(assertionStack, stack); | ||
const lambdaFunctionTest = integ.assertions.invokeFunction({ | ||
functionName: 'GetEniIntegRunnerFunction', | ||
}); | ||
lambdaFunctionTest.expect(ExpectedResult.objectLike({ StatusCode: 200 })); | ||
lambdaFunctionTest.assertAtPath('Payload.body.message', ExpectedResult.stringLikeRegexp('Metrics found')); | ||
|
||
app.synth(); |