From b3f43e68d8564ba4834cf4fce15cb643563362fa Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Mon, 29 Mar 2021 14:39:05 +0100 Subject: [PATCH 1/2] fix(core): BundlingDockerImage.fromAsset() does not return a BundlingDockerImage A previous change missed to fix the 'return' statement on this method. --- packages/@aws-cdk/core/lib/bundling.ts | 4 ++-- packages/@aws-cdk/core/test/bundling.test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/core/lib/bundling.ts b/packages/@aws-cdk/core/lib/bundling.ts index 5b4a579caf8f1..bd9299a5a990d 100644 --- a/packages/@aws-cdk/core/lib/bundling.ts +++ b/packages/@aws-cdk/core/lib/bundling.ts @@ -157,8 +157,8 @@ export class BundlingDockerImage { * * @deprecated use DockerImage.fromBuild() */ - public static fromAsset(path: string, options: DockerBuildOptions = {}) { - DockerImage.fromBuild(path, options) as BundlingDockerImage; + public static fromAsset(path: string, options: DockerBuildOptions = {}): BundlingDockerImage { + return DockerImage.fromBuild(path, options); } /** @param image The Docker image */ diff --git a/packages/@aws-cdk/core/test/bundling.test.ts b/packages/@aws-cdk/core/test/bundling.test.ts index 1c909142b3127..b31ab401129eb 100644 --- a/packages/@aws-cdk/core/test/bundling.test.ts +++ b/packages/@aws-cdk/core/test/bundling.test.ts @@ -173,6 +173,24 @@ nodeunitShim({ test.done(); }, + 'fromAsset'(test: Test) { + sinon.stub(child_process, 'spawnSync').returns({ + status: 0, + stderr: Buffer.from('stderr'), + stdout: Buffer.from('sha256:1234567890abcdef'), + pid: 123, + output: ['stdout', 'stderr'], + signal: null, + }); + + const imagePath = path.join(__dirname, 'fs/fixtures/test1'); + const image = BundlingDockerImage.fromAsset(imagePath, { + file: 'my-dockerfile', + }); + test.equals(image.image, 'cdk-6e2d258c76add1c2574af94769b996e20faf52da8e010a9725c04c15ddb146e5'); + test.done(); + }, + 'custom entrypoint is passed through to docker exec'(test: Test) { const spawnSyncStub = sinon.stub(child_process, 'spawnSync').returns({ status: 0, From 0045cead9f48c36e19990945511a0e5899940c53 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Mon, 29 Mar 2021 15:53:14 +0100 Subject: [PATCH 2/2] fix unit test --- packages/@aws-cdk/core/test/bundling.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/test/bundling.test.ts b/packages/@aws-cdk/core/test/bundling.test.ts index b31ab401129eb..97b9d5969c2b3 100644 --- a/packages/@aws-cdk/core/test/bundling.test.ts +++ b/packages/@aws-cdk/core/test/bundling.test.ts @@ -187,7 +187,8 @@ nodeunitShim({ const image = BundlingDockerImage.fromAsset(imagePath, { file: 'my-dockerfile', }); - test.equals(image.image, 'cdk-6e2d258c76add1c2574af94769b996e20faf52da8e010a9725c04c15ddb146e5'); + test.ok(image); + test.ok(image.image); test.done(); },