-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
836b786
commit fa12cff
Showing
13 changed files
with
1,525 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
npm-debug.log | ||
dist/ | ||
/node_modules/ | ||
/npm-debug.log | ||
/dist/ | ||
/cdk.out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "npx tsx --no-warnings cdk/e2e.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Provides the infrastructure to run the end-to-end tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { App } from 'aws-cdk-lib' | ||
import { TestStack } from './TestStack.js' | ||
|
||
export class TestApp extends App { | ||
public constructor( | ||
id: string, | ||
args: ConstructorParameters<typeof TestStack>[2], | ||
) { | ||
super({ | ||
context: { | ||
isTest: true, | ||
}, | ||
}) | ||
|
||
new TestStack(this, id, args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
App, | ||
CfnOutput, | ||
Duration, | ||
aws_lambda as Lambda, | ||
Stack, | ||
} from 'aws-cdk-lib' | ||
import { LambdaLogGroup, LambdaSource } from '../src/cdk.js' | ||
import type { PackedLayer } from '../src/layer.js' | ||
import type { TestLambdas } from './packTestLambdas.js' | ||
|
||
export class TestStack extends Stack { | ||
public constructor( | ||
parent: App, | ||
id: string, | ||
{ | ||
lambdaSources, | ||
layer, | ||
}: { | ||
lambdaSources: TestLambdas | ||
layer: PackedLayer | ||
}, | ||
) { | ||
super(parent, id, {}) | ||
|
||
const baseLayer = new Lambda.LayerVersion(this, 'baseLayer', { | ||
layerVersionName: `${Stack.of(this).stackName}-baseLayer`, | ||
code: new LambdaSource(this, { | ||
id: 'baseLayer', | ||
zipFile: layer.layerZipFile, | ||
hash: layer.hash, | ||
}).code, | ||
compatibleArchitectures: [Lambda.Architecture.ARM_64], | ||
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X], | ||
}) | ||
|
||
const fn = new Lambda.Function(this, 'fn', { | ||
handler: lambdaSources.test.handler, | ||
architecture: Lambda.Architecture.ARM_64, | ||
runtime: Lambda.Runtime.NODEJS_20_X, | ||
timeout: Duration.seconds(1), | ||
memorySize: 1792, | ||
code: new LambdaSource(this, lambdaSources.test).code, | ||
description: 'Returns a ULID', | ||
environment: { | ||
NODE_NO_WARNINGS: '1', | ||
}, | ||
layers: [baseLayer], | ||
...new LambdaLogGroup(this, 'fnLogs'), | ||
}) | ||
|
||
const url = fn.addFunctionUrl({ | ||
authType: Lambda.FunctionUrlAuthType.NONE, | ||
}) | ||
|
||
new CfnOutput(this, 'lambdaURL', { | ||
exportName: `${this.stackName}:lambdaURL`, | ||
description: 'API endpoint', | ||
value: url.url, | ||
}) | ||
} | ||
} | ||
|
||
export type StackOutputs = { | ||
lambdaURL: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { packLayer, type PackedLayer } from '../src/layer.js' | ||
|
||
export const pack = async (): Promise<PackedLayer> => | ||
packLayer({ | ||
id: 'baseLayer', | ||
dependencies: ['id128'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { TestApp } from './TestApp.js' | ||
import { pack as packBaseLayer } from './baseLayer.js' | ||
import { packTestLambdas } from './packTestLambdas.js' | ||
import { fromEnv } from '@nordicsemiconductor/from-env' | ||
const { stackName } = fromEnv({ | ||
stackName: 'STACK_NAME', | ||
})(process.env) | ||
|
||
new TestApp(stackName, { | ||
lambdaSources: await packTestLambdas(), | ||
layer: await packBaseLayer(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { APIGatewayProxyResultV2 } from 'aws-lambda' | ||
import id128 from 'id128' | ||
|
||
export const handler = async (): Promise<APIGatewayProxyResultV2> => ({ | ||
statusCode: 201, | ||
body: id128.Ulid.generate().toCanonical(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { PackedLambda } from '../src/packLambda.js' | ||
import { packLambdaFromPath } from '../src/packLambdaFromPath.js' | ||
|
||
export type TestLambdas = { | ||
test: PackedLambda | ||
} | ||
|
||
export const packTestLambdas = async (): Promise<TestLambdas> => ({ | ||
test: await packLambdaFromPath('test', 'cdk/lambda.ts'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, it } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { stackOutput } from '@nordicsemiconductor/cloudformation-helpers' | ||
import { CloudFormationClient } from '@aws-sdk/client-cloudformation' | ||
import type { StackOutputs } from './cdk/TestStack.js' | ||
import { fromEnv } from '@nordicsemiconductor/from-env' | ||
|
||
void describe('end-to-end tests', () => { | ||
void it('should return an ULID', async () => { | ||
const { stackName } = fromEnv({ | ||
stackName: 'STACK_NAME', | ||
})(process.env) | ||
const { lambdaURL } = await stackOutput( | ||
new CloudFormationClient({}), | ||
)<StackOutputs>(stackName) | ||
|
||
const res = await fetch(new URL(lambdaURL)) | ||
assert.equal(res.ok, true) | ||
assert.equal(res.status, 201) | ||
assert.match(await res.text(), /^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/) | ||
}) | ||
}) |
Oops, something went wrong.