Skip to content

Commit d9f9022

Browse files
author
Elad Ben-Israel
committed
make code v1/v2 aware
1 parent f8f3244 commit d9f9022

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'fs';
1+
import { readdirSync, readFileSync, existsSync } from 'fs';
22
import * as path from 'path';
33
import { Match, Template } from '@aws-cdk/assertions';
44
import * as cloudfront from '@aws-cdk/aws-cloudfront';
@@ -1099,7 +1099,7 @@ test('Source.data() can be used to create a file with string contents', () => {
10991099
});
11001100

11011101
const result = app.synth();
1102-
const content = readDataFile(result, 'c5b1c01fc092abf1da35f6772e7c507e566aaa69404025c080ba074c69741755', 'my/path.txt');
1102+
const content = readDataFile(result, 'my/path.txt');
11031103
expect(content).toStrictEqual('hello, world');
11041104
});
11051105

@@ -1121,7 +1121,7 @@ test('Source.jsonData() can be used to create a file with a JSON object', () =>
11211121
});
11221122

11231123
const result = app.synth();
1124-
const obj = JSON.parse(readDataFile(result, '6a9e1763f42401799363d87d16b238c89bf75a56f2a3f67498a3224573062b0c', 'app-config.json'));
1124+
const obj = JSON.parse(readDataFile(result, 'app-config.json'));
11251125
expect(obj).toStrictEqual({
11261126
foo: 'bar',
11271127
sub: {
@@ -1138,8 +1138,14 @@ test('Source.jsonData() can be used to create a file with a JSON object', () =>
11381138
});
11391139

11401140

1141-
function readDataFile(casm: cxapi.CloudAssembly, assetId: string, filePath: string): string {
1142-
const asset = casm.stacks[0].assets.find(a => a.id === assetId);
1143-
if (!asset) { throw new Error('Asset not found'); }
1144-
return readFileSync(path.join(casm.directory, asset.path, filePath), 'utf-8');
1141+
function readDataFile(casm: cxapi.CloudAssembly, relativePath: string): string {
1142+
const assetDirs = readdirSync(casm.directory).filter(f => f.startsWith('asset.'));
1143+
for (const dir of assetDirs) {
1144+
const candidate = path.join(casm.directory, dir, relativePath);
1145+
if (existsSync(candidate)) {
1146+
return readFileSync(candidate, 'utf8');
1147+
}
1148+
}
1149+
1150+
throw new Error(`File ${relativePath} not found in any of the assets of the assembly`);
11451151
}

0 commit comments

Comments
 (0)