Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jogold committed Jun 11, 2020
1 parent 6f186da commit 5ba67fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/@aws-cdk/core/test/test.bundling.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as child_process from 'child_process';
import { Test } from 'nodeunit';
import * as os from 'os';
import * as sinon from 'sinon';
import { BundlingDockerImage } from '../lib';

const userInfo = os.userInfo();

export = {
'tearDown'(callback: any) {
sinon.restore();
Expand Down Expand Up @@ -32,7 +35,7 @@ export = {

test.ok(spawnSyncStub.calledWith('docker', [
'run', '--rm',
'-u', '1000:1000',
'-u', `${userInfo.uid}:${userInfo.gid}`,
'-v', '/host-path:/container-path',
'--env', 'VAR1=value1',
'--env', 'VAR2=value2',
Expand Down Expand Up @@ -69,7 +72,7 @@ export = {

test.ok(spawnSyncStub.secondCall.calledWith('docker', [
'run', '--rm',
'-u', '1000:1000',
'-u', `${userInfo.uid}:${userInfo.gid}`,
imageId,
]));
test.done();
Expand Down
30 changes: 24 additions & 6 deletions packages/@aws-cdk/core/test/test.staging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cxapi from '@aws-cdk/cx-api';
import * as fs from 'fs';
import { Test } from 'nodeunit';
import * as os from 'os';
import * as path from 'path';
import { App, AssetHashType, AssetStaging, BundlingDockerImage, Stack } from '../lib';

Expand All @@ -12,6 +13,9 @@ enum DockerStubCommand {
SUCCESS_NO_OUTPUT = 'DOCKER_STUB_SUCCESS_NO_OUTPUT'
}

const userInfo = os.userInfo();
const USER_ARG = `-u ${userInfo.uid}:${userInfo.gid}`;

// this is a way to provide a custom "docker" command for staging.
process.env.CDK_DOCKER = `${__dirname}/docker-stub.sh`;

Expand Down Expand Up @@ -111,7 +115,10 @@ export = {

// THEN
const assembly = app.synth();
test.deepEqual(readDockerStubInput(), 'run --rm -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS');
test.deepEqual(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);
test.deepEqual(fs.readdirSync(assembly.directory), [
'asset.2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00',
'cdk.out',
Expand All @@ -138,8 +145,10 @@ export = {
},
}), /Bundling did not produce any output/);

test.equal(readDockerStubInput(),
'run --rm -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS_NO_OUTPUT');
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS_NO_OUTPUT`,
);
test.done();
},

Expand All @@ -160,7 +169,10 @@ export = {
});

// THEN
test.equal(readDockerStubInput(), 'run --rm -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS');
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);
test.equal(asset.assetHash, '33cbf2cae5432438e0f046bc45ba8c3cef7b6afcf47b59d1c183775c1918fb1f');

test.done();
Expand Down Expand Up @@ -201,7 +213,10 @@ export = {
assetHash: 'my-custom-hash',
assetHashType: AssetHashType.BUNDLE,
}), /Cannot specify `bundle` for `assetHashType`/);
test.equal(readDockerStubInput(), 'run --rm -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS');
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input alpine DOCKER_STUB_SUCCESS`,
);

test.done();
},
Expand Down Expand Up @@ -252,7 +267,10 @@ export = {
command: [ DockerStubCommand.FAIL ],
},
}), /Failed to run bundling Docker image for asset stack\/Asset/);
test.equal(readDockerStubInput(), 'run --rm -v /input:/asset-input -v /output:/asset-output -w /asset-input this-is-an-invalid-docker-image DOCKER_STUB_FAIL');
test.equal(
readDockerStubInput(),
`run --rm ${USER_ARG} -v /input:/asset-input -v /output:/asset-output -w /asset-input this-is-an-invalid-docker-image DOCKER_STUB_FAIL`,
);

test.done();
},
Expand Down

0 comments on commit 5ba67fa

Please sign in to comment.