Skip to content

Commit

Permalink
fix(core,cx-api): docker bundling fails during tests on macOS (#10620)
Browse files Browse the repository at this point in the history
When running unit tests `outdir` defaults to a temporary directory in
the system temp directory. On macOS `os.tmpdir()` is a symlink. In 
`v1.61.0` we changed the bundling directory to be a directory inside
`outdir` (`cdk.out`). This makes Docker bundling fail during tests.

Fix it by using `fs.realpathSync`.

Closes #10262


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold committed Oct 1, 2020
1 parent fa50369 commit 0331508
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cx-api/lib/cloud-assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,5 @@ function ignore(_x: any) {
* Turn the given optional output directory into a fixed output directory
*/
function determineOutputDirectory(outdir?: string) {
return outdir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'cdk.out'));
return outdir ?? fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'cdk.out'));
}
8 changes: 7 additions & 1 deletion packages/@aws-cdk/cx-api/test/cloud-assembly-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ test('outdir must be a directory', () => {
expect(() => new cxapi.CloudAssemblyBuilder(__filename)).toThrow('must be a directory');
});

test('outdir defaults to a temporary directory', () => {
const assembly = new cxapi.CloudAssemblyBuilder();
const realTmpDir = fs.realpathSync(os.tmpdir());
expect(assembly.outdir).toMatch(new RegExp(`^${path.join(realTmpDir, 'cdk.out')}`));
});

test('duplicate missing values with the same key are only reported once', () => {
const outdir = fs.mkdtempSync(path.join(os.tmpdir(), 'cloud-assembly-builder-tests'));
const session = new cxapi.CloudAssemblyBuilder(outdir);
Expand Down Expand Up @@ -224,4 +230,4 @@ test('artifcats are written in topological order', () => {
expect(artifactsIds.indexOf('artifact-A')).toBeLessThan(artifactsIds.indexOf('artifact-C'));
expect(artifactsIds.indexOf('artifact-B')).toBeLessThan(artifactsIds.indexOf('artifact-C'));
expect(artifactsIds.indexOf('artifact-C')).toBeLessThan(artifactsIds.indexOf('artifact-D'));
});
});

0 comments on commit 0331508

Please sign in to comment.