Skip to content

Commit e5b7813

Browse files
authored
chore(eslint-plugin): rule against invalid paths (#28828)
This is a follow up to #28658, #28772, and #28760. We had to fix multiple places where that file path extended beyond the package itself into other areas of the local repository (that would not be available after packaging). This caused myriad issues at synth time with `file not found` errors. This PR introduces a linter rule with the following specifications: - no inefficient paths, i.e. no going backwards multiple times. Ex. `path.join(__dirname, '..', 'folder', '..', 'another-folder')`. This should and can be easily simplified - no paths that go backwards past a `package.json` file. This should catch the instances we faced next time. The `yarn lint` command on `aws-cdk-lib` took 51.47s seconds without this new rule and 53.32s seconds with the rule enabled. The difference of ~2 seconds shouldn't be a hindrance in this case but I am happy to look for additional efficiencies in the rule I've written. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 610fce1 commit e5b7813

File tree

72 files changed

+221
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+221
-92
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-authorizers/test/http/integ.lambda.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const stack = new Stack(app, 'AuthorizerInteg');
1818
const authHandler = new lambda.Function(stack, 'auth-function', {
1919
runtime: lambda.Runtime.NODEJS_18_X,
2020
handler: 'index.handler',
21-
code: lambda.Code.fromAsset(path.join(__dirname, '../auth-handler')),
21+
code: lambda.Code.fromAsset(path.join(__dirname, '..', 'auth-handler')),
2222
});
2323

2424
const authorizer = new HttpLambdaAuthorizer('LambdaAuthorizer', authHandler, {
@@ -41,7 +41,7 @@ const httpApiWithDefaultAuthorizer = new HttpApi(stack, 'MyHttpApiWithDefaultAut
4141
const handler = new lambda.Function(stack, 'lambda', {
4242
runtime: lambda.Runtime.NODEJS_18_X,
4343
handler: 'index.handler',
44-
code: lambda.AssetCode.fromAsset(path.join(__dirname, '../integ.lambda.handler')),
44+
code: lambda.AssetCode.fromAsset(path.join(__dirname, '..', 'integ.lambda.handler')),
4545
});
4646

4747
httpApi.addRoutes({

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-authorizers/test/http/integ.user-pool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const httpApiWithDefaultAuthorizer = new HttpApi(stack, 'MyHttpApiWithDefaultAut
3131
const handler = new lambda.Function(stack, 'lambda', {
3232
runtime: lambda.Runtime.NODEJS_18_X,
3333
handler: 'index.handler',
34-
code: lambda.AssetCode.fromAsset(path.join(__dirname, '../integ.user-pool.handler')),
34+
code: lambda.AssetCode.fromAsset(path.join(__dirname, '..', 'integ.user-pool.handler')),
3535
});
3636

3737
httpApi.addRoutes({

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-lambda.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const api = new appsync.GraphqlApi(stack, 'LambdaAPI', {
2828
});
2929

3030
const func = new lambda.Function(stack, 'func', {
31-
code: lambda.Code.fromAsset(path.join(__dirname, 'verify/lambda-tutorial')),
31+
code: lambda.Code.fromAsset(path.join(__dirname, 'verify', 'lambda-tutorial')),
3232
handler: 'lambda-tutorial.handler',
3333
runtime: STANDARD_NODEJS_RUNTIME,
3434
});

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.js-resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const integ = new IntegTest(app, 'JsResolverIntegTest', { testCases: [stack] });
5858
* Handler that calls our api with an `addTest` Mutation
5959
*/
6060
const invoke = new lambda.Function(stack, 'InvokeApi', {
61-
code: lambda.Code.fromAsset(path.join(__dirname, 'integ-assets/js-resolver-assertion')),
61+
code: lambda.Code.fromAsset(path.join(__dirname, 'integ-assets', 'js-resolver-assertion')),
6262
handler: 'index.handler',
6363
runtime: lambda.Runtime.NODEJS_18_X,
6464
});

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.lambda-auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GraphQLApiLambdaAuthStack extends cdk.Stack {
1212

1313
const func = new lambda.Function(this, 'func', {
1414
code: lambda.Code.fromAsset(
15-
path.join(__dirname, 'verify/lambda-tutorial'),
15+
path.join(__dirname, 'verify', 'lambda-tutorial'),
1616
),
1717
handler: 'lambda-tutorial.handler',
1818
runtime: STANDARD_NODEJS_RUNTIME,

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const bucket = new s3.Bucket(stack, 'PipelineBucket', {
3232
});
3333

3434
const artifact = new deploy.BucketDeployment(stack, 'DeployApp', {
35-
sources: [deploy.Source.asset(path.join(__dirname, 'assets/nodejs.zip'))],
35+
sources: [deploy.Source.asset(path.join(__dirname, 'assets', 'nodejs.zip'))],
3636
destinationBucket: bucket,
3737
extract: false,
3838
});

packages/@aws-cdk-testing/framework-integ/test/aws-ecs/test/ec2/integ.environment-file.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDefinition', {
4949
// deploy an envfile to S3 and delete when the bucket is deleted
5050
const envFileDeployment = new s3deployment.BucketDeployment(stack, 'EnvFileDeployment', {
5151
destinationBucket: bucket,
52-
sources: [s3deployment.Source.asset(path.join(__dirname, '../demo-envfiles'))],
52+
sources: [s3deployment.Source.asset(path.join(__dirname, '..', 'demo-envfiles'))],
5353
});
5454

5555
// define container with envfiles - one from local disk and another from S3
5656
const containerDefinition = new ecs.ContainerDefinition(stack, 'Container', {
5757
environmentFiles: [
58-
ecs.EnvironmentFile.fromAsset(path.join(__dirname, '../demo-envfiles/test-envfile.env')),
58+
ecs.EnvironmentFile.fromAsset(path.join(__dirname, '..', 'demo-envfiles', 'test-envfile.env')),
5959
ecs.EnvironmentFile.fromBucket(bucket, 'test-envfile.env'),
6060
],
6161
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),

packages/@aws-cdk-testing/framework-integ/test/aws-servicecatalog/test/integ.two-products.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TestAssetProductStack1 extends servicecatalog.ProductStack {
6464

6565
new lambda.Function(this, 'HelloHandler', {
6666
runtime: lambda.Runtime.PYTHON_3_9,
67-
code: lambda.Code.fromAsset(path.join(__dirname, './assets')),
67+
code: lambda.Code.fromAsset(path.join(__dirname, 'assets')),
6868
handler: 'index.handler',
6969
});
7070
}
@@ -76,7 +76,7 @@ class TestAssetProductStack2 extends servicecatalog.ProductStack {
7676

7777
new lambda.Function(this, 'HelloHandler2', {
7878
runtime: lambda.Runtime.PYTHON_3_9,
79-
code: lambda.Code.fromAsset(path.join(__dirname, './assetsv2')),
79+
code: lambda.Code.fromAsset(path.join(__dirname, 'assetsv2')),
8080
handler: 'index.handler',
8181
});
8282
}

packages/@aws-cdk/app-staging-synthesizer-alpha/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ import { Asset } from 'aws-cdk-lib/aws-s3-assets';
213213
declare const stack: Stack;
214214
const asset = new Asset(stack, 'deploy-time-asset', {
215215
deployTime: true,
216-
path: path.join(__dirname, './deploy-time-asset'),
216+
path: path.join(__dirname, 'deploy-time-asset'),
217217
});
218218
```
219219

packages/@aws-cdk/aws-amplify-alpha/test/branch.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test('with env vars', () => {
105105
test('with asset deployment', () => {
106106
// WHEN
107107
const asset = new Asset(app, 'SampleAsset', {
108-
path: path.join(__dirname, './test-asset'),
108+
path: path.join(__dirname, 'test-asset'),
109109
});
110110
app.addBranch('dev', { asset });
111111

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestStack extends Stack {
1010
super(scope, id, props);
1111

1212
const asset = new Asset(this, 'SampleAsset', {
13-
path: path.join(__dirname, './test-asset'),
13+
path: path.join(__dirname, 'test-asset'),
1414
});
1515

1616
const amplifyApp = new amplify.App(this, 'App', {});

packages/@aws-cdk/aws-apprunner-alpha/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ You can specify whether to enable continuous integration from the source reposit
7474
import * as assets from 'aws-cdk-lib/aws-ecr-assets';
7575

7676
const imageAsset = new assets.DockerImageAsset(this, 'ImageAssets', {
77-
directory: path.join(__dirname, './docker.assets'),
77+
directory: path.join(__dirname, 'docker.assets'),
7878
});
7979
new apprunner.Service(this, 'Service', {
8080
source: apprunner.Source.fromAsset({

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-ecr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const stack = new cdk.Stack(app, 'integ-apprunner');
99

1010
// Scenario 3: Create the service from local code assets
1111
const imageAsset = new assets.DockerImageAsset(stack, 'ImageAssets', {
12-
directory: path.join(__dirname, './docker.assets'),
12+
directory: path.join(__dirname, 'docker.assets'),
1313
});
1414
const service3 = new Service(stack, 'Service3', {
1515
source: Source.fromAsset({

packages/@aws-cdk/aws-apprunner-alpha/test/service.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ test('create a service with local assets(image repository type: ECR)', () => {
574574
const stack = new cdk.Stack(app, 'demo-stack');
575575
// WHEN
576576
const dockerAsset = new ecr_assets.DockerImageAsset(stack, 'Assets', {
577-
directory: path.join(__dirname, './docker.assets'),
577+
directory: path.join(__dirname, 'docker.assets'),
578578
});
579579
new apprunner.Service(stack, 'DemoService', {
580580
source: apprunner.Source.fromAsset({
@@ -864,7 +864,7 @@ test('custom IAM access role and instance role are allowed', () => {
864864
const stack = new cdk.Stack(app, 'demo-stack');
865865
// WHEN
866866
const dockerAsset = new ecr_assets.DockerImageAsset(stack, 'Assets', {
867-
directory: path.join(__dirname, './docker.assets'),
867+
directory: path.join(__dirname, 'docker.assets'),
868868
});
869869
new apprunner.Service(stack, 'DemoService', {
870870
source: apprunner.Source.fromAsset({
@@ -1177,7 +1177,7 @@ test('autoDeploymentsEnabled flag is set true', () => {
11771177
const stack = new cdk.Stack(app, 'demo-stack');
11781178
// WHEN
11791179
const dockerAsset = new ecr_assets.DockerImageAsset(stack, 'Assets', {
1180-
directory: path.join(__dirname, './docker.assets'),
1180+
directory: path.join(__dirname, 'docker.assets'),
11811181
});
11821182
new apprunner.Service(stack, 'DemoService', {
11831183
source: apprunner.Source.fromAsset({

packages/@aws-cdk/aws-gamelift-alpha/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ match is made after 30 seconds, gradually relax the skill requirements.
9999
```ts
100100
new gamelift.MatchmakingRuleSet(this, 'RuleSet', {
101101
matchmakingRuleSetName: 'my-test-ruleset',
102-
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset/ruleset.json')),
102+
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json')),
103103
});
104104
```
105105

packages/@aws-cdk/aws-gamelift-alpha/test/integ.matchmaking-ruleset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestStack extends cdk.Stack {
1111

1212
const ruleSet = new gamelift.MatchmakingRuleSet(this, 'MatchmakingRuleSet', {
1313
matchmakingRuleSetName: 'my-test-ruleset',
14-
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset/ruleset.json')),
14+
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json')),
1515
});
1616

1717
new CfnOutput(this, 'MatchmakingRuleSetArn', { value: ruleSet.matchmakingRuleSetArn });

packages/@aws-cdk/aws-gamelift-alpha/test/integ.queued-matchmaking-configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestStack extends cdk.Stack {
1212

1313
const ruleSet = new gamelift.MatchmakingRuleSet(this, 'QueuedMatchmakingConfiguration', {
1414
matchmakingRuleSetName: 'my-test-ruleset',
15-
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset/ruleset.json')),
15+
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json')),
1616
});
1717

1818
const build = new gamelift.Build(this, 'Build', {

packages/@aws-cdk/aws-gamelift-alpha/test/integ.standalone-matchmaking-configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestStack extends cdk.Stack {
1111

1212
const ruleSet = new gamelift.MatchmakingRuleSet(this, 'StandaloneMatchmakingConfiguration', {
1313
matchmakingRuleSetName: 'my-test-ruleset',
14-
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset/ruleset.json')),
14+
content: gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json')),
1515
});
1616

1717
const matchmakingConfiguration = new gamelift.StandaloneMatchmakingConfiguration(this, 'MyStandaloneMatchmakingConfiguration', {

packages/@aws-cdk/aws-gamelift-alpha/test/matchmaking-ruleset-body.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ describe('MatchmakingRuleSetBody', () => {
3535

3636
describe('gamelift.MatchmakingRuleSetBody.fromJsonFile', () => {
3737
test('new RuleSetBody from Json file', () => {
38-
const ruleSet = gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset/ruleset.json'));
38+
const ruleSet = gamelift.RuleSetContent.fromJsonFile(path.join(__dirname, 'my-ruleset', 'ruleset.json'));
3939
const content = ruleSet.bind(stack);
40-
const result = JSON.parse(fs.readFileSync(path.join(__dirname, 'my-ruleset/ruleset.json')).toString());
40+
const result = JSON.parse(fs.readFileSync(path.join(__dirname, 'my-ruleset', 'ruleset.json')).toString());
4141
expect(content.ruleSetBody).toEqual(JSON.stringify(result));
4242
});
4343

4444
test('fails if file not exist', () => {
45-
const content = path.join(__dirname, 'my-ruleset/file-not-exist.json');
45+
const content = path.join(__dirname, 'my-ruleset', 'file-not-exist.json');
4646
expect(() => gamelift.RuleSetContent.fromJsonFile(content))
4747
.toThrow(`RuleSet path does not exist, please verify it, actual ${content}`);
4848
});

packages/@aws-cdk/aws-glue-alpha/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ new glue.Job(this, 'PythonSparkStreamingJob', {
6060
executable: glue.JobExecutable.pythonStreaming({
6161
glueVersion: glue.GlueVersion.V4_0,
6262
pythonVersion: glue.PythonVersion.THREE,
63-
script: glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py')),
63+
script: glue.Code.fromAsset(path.join(__dirname, 'job-script', 'hello_world.py')),
6464
}),
6565
description: 'an example Python Streaming job',
6666
});
@@ -97,7 +97,7 @@ new glue.Job(this, 'RayJob', {
9797
glueVersion: glue.GlueVersion.V4_0,
9898
pythonVersion: glue.PythonVersion.THREE_NINE,
9999
runtime: glue.Runtime.RAY_TWO_FOUR,
100-
script: glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py')),
100+
script: glue.Code.fromAsset(path.join(__dirname, 'job-script', 'hello_world.py')),
101101
}),
102102
workerType: glue.WorkerType.Z_2X,
103103
workerCount: 2,
@@ -118,7 +118,7 @@ new glue.Job(this, 'EnableSparkUI', {
118118
executable: glue.JobExecutable.pythonEtl({
119119
glueVersion: glue.GlueVersion.V3_0,
120120
pythonVersion: glue.PythonVersion.THREE,
121-
script: glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py')),
121+
script: glue.Code.fromAsset(path.join(__dirname, 'job-script', 'hello_world.py')),
122122
}),
123123
});
124124
```

packages/@aws-cdk/aws-glue-alpha/test/code.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('Code', () => {
8585
});
8686

8787
describe('.fromAsset()', () => {
88-
const filePath = path.join(__dirname, 'job-script/hello_world.py');
88+
const filePath = path.join(__dirname, 'job-script', 'hello_world.py');
8989
const directoryPath = path.join(__dirname, 'job-script');
9090

9191
beforeEach(() => {

packages/@aws-cdk/aws-glue-alpha/test/integ.job-python-shell.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const app = new cdk.App();
2222

2323
const stack = new cdk.Stack(app, 'aws-glue-job-python-shell');
2424

25-
const script = glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py'));
25+
const script = glue.Code.fromAsset(path.join(__dirname, 'job-script', 'hello_world.py'));
2626

2727
new glue.Job(stack, 'ShellJob', {
2828
jobName: 'ShellJob',

packages/@aws-cdk/aws-glue-alpha/test/integ.job.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const app = new cdk.App();
2121

2222
const stack = new cdk.Stack(app, 'aws-glue-job');
2323

24-
const script = glue.Code.fromAsset(path.join(__dirname, 'job-script/hello_world.py'));
24+
const script = glue.Code.fromAsset(path.join(__dirname, 'job-script', 'hello_world.py'));
2525

2626
[glue.GlueVersion.V2_0, glue.GlueVersion.V3_0, glue.GlueVersion.V4_0].forEach((glueVersion) => {
2727
const etlJob = new glue.Job(stack, 'EtlJob' + glueVersion.name, {

packages/@aws-cdk/aws-lambda-go-alpha/lib/bundling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class Bundling implements cdk.BundlingOptions {
143143
// Docker bundling
144144
const shouldBuildImage = props.forcedDockerBundling || !Bundling.runsLocally;
145145
this.image = shouldBuildImage
146-
? props.dockerImage ?? cdk.DockerImage.fromBuild(path.join(__dirname, '../lib'), {
146+
? props.dockerImage ?? cdk.DockerImage.fromBuild(path.join(__dirname, '..', 'lib'), {
147147
buildArgs: {
148148
...props.buildArgs ?? {},
149149
IMAGE: Runtime.GO_1_X.bundlingImage.image, // always use the GO_1_X build image

packages/@aws-cdk/aws-lambda-go-alpha/test/docker.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33

44
const docker = process.env.CDK_DOCKER ?? 'docker';
55
beforeAll(() => {
6-
spawnSync(docker, ['build', '-t', 'golang', path.join(__dirname, '../lib')]);
6+
spawnSync(docker, ['build', '-t', 'golang', path.join(__dirname, '..', 'lib')]);
77
});
88

99
test('golang is available', async () => {

packages/@aws-cdk/aws-lambda-go-alpha/test/function.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ beforeEach(() => {
2727
test('GoFunction with defaults', () => {
2828
// WHEN
2929
new GoFunction(stack, 'handler', {
30-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
30+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
3131
});
3232

3333
expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
@@ -43,7 +43,7 @@ test('GoFunction with defaults', () => {
4343
test('GoFunction with using provided runtime', () => {
4444
// WHEN
4545
new GoFunction(stack, 'handler', {
46-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
46+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
4747
runtime: Runtime.PROVIDED,
4848
});
4949

@@ -60,7 +60,7 @@ test('GoFunction with using provided runtime', () => {
6060
test('GoFunction with using golang runtime', () => {
6161
// WHEN
6262
new GoFunction(stack, 'handler', {
63-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
63+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
6464
runtime: Runtime.GO_1_X,
6565
});
6666

@@ -77,7 +77,7 @@ test('GoFunction with using golang runtime', () => {
7777
test('GoFunction with container env vars', () => {
7878
// WHEN
7979
new GoFunction(stack, 'handler', {
80-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
80+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
8181
bundling: {
8282
environment: {
8383
KEY: 'VALUE',
@@ -94,15 +94,15 @@ test('GoFunction with container env vars', () => {
9494

9595
test('throws with the wrong runtime family', () => {
9696
expect(() => new GoFunction(stack, 'handler', {
97-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
97+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
9898
runtime: Runtime.PYTHON_3_8,
9999
})).toThrow(/Only `go` and `provided` runtimes are supported/);
100100
});
101101

102102
test('resolves entry to an absolute path', () => {
103103
// WHEN
104104
new GoFunction(stack, 'fn', {
105-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api/main.go'),
105+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api', 'main.go'),
106106
});
107107

108108
expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({
@@ -112,21 +112,21 @@ test('resolves entry to an absolute path', () => {
112112

113113
test('throws with no existing go.mod file', () => {
114114
expect(() => new GoFunction(stack, 'handler', {
115-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
115+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
116116
moduleDir: '/does/not/exist/go.mod',
117117
})).toThrow(/go.mod file at \/does\/not\/exist\/go.mod doesn't exist/);
118118
});
119119

120120
test('throws with incorrect moduleDir file', () => {
121121
expect(() => new GoFunction(stack, 'handler', {
122-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
122+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
123123
moduleDir: '/does/not/exist.mod',
124124
})).toThrow(/moduleDir is specifying a file that is not go.mod/);
125125
});
126126

127127
test('custom moduleDir can be used', () => {
128128
new GoFunction(stack, 'handler', {
129-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
129+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
130130
moduleDir: path.join(__dirname, 'lambda-handler-vendor'),
131131
});
132132

@@ -137,8 +137,8 @@ test('custom moduleDir can be used', () => {
137137

138138
test('custom moduleDir with file path can be used', () => {
139139
new GoFunction(stack, 'handler', {
140-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
141-
moduleDir: path.join(__dirname, 'lambda-handler-vendor/go.mod'),
140+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
141+
moduleDir: path.join(__dirname, 'lambda-handler-vendor', 'go.mod'),
142142
});
143143

144144
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {

packages/@aws-cdk/aws-lambda-go-alpha/test/integ.function.provided.al2023.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestStack extends Stack {
1515
super(scope, id, props);
1616

1717
new lambda.GoFunction(this, 'go-handler-docker', {
18-
entry: path.join(__dirname, 'lambda-handler-vendor/cmd/api'),
18+
entry: path.join(__dirname, 'lambda-handler-vendor', 'cmd', 'api'),
1919
runtime: Runtime.PROVIDED_AL2023,
2020
bundling: {
2121
forcedDockerBundling: true,

0 commit comments

Comments
 (0)