Skip to content

Commit

Permalink
Merge branch 'master' into ecs-can-access-container-instance-role
Browse files Browse the repository at this point in the history
  • Loading branch information
daschaa authored May 27, 2022
2 parents 6c8c11c + c274c2f commit 3635050
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
7 changes: 7 additions & 0 deletions packages/@aws-cdk/integ-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

## Overview

This tool has been created to be used initially by this repo (aws/aws-cdk). Long term the goal is
for this tool to be a general tool that can be used for running CDK integration tests. We are
publishing this tool so that it can be used by the community and we would love to receive feedback
on use cases that the tool should support, or issues that prevent the tool from being used in your
library.

This tool is meant to be used with the [integ-tests](https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/integ-tests) library.

## Usage

Expand Down
9 changes: 7 additions & 2 deletions packages/@aws-cdk/integ-runner/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ async function main() {

let failedSnapshots: IntegTestWorkerConfig[] = [];
if (argv['max-workers'] < testRegions.length * (profiles ?? [1]).length) {
logger.warning('You are attempting to run %s tests in parallel, but only have %s workers. Not all of your profiles+regions will be utilized', argv.profiles*argv['parallel-regions'], argv['max-workers']);
logger.warning('You are attempting to run %s tests in parallel, but only have %s workers. Not all of your profiles+regions will be utilized', argv.profiles * argv['parallel-regions'], argv['max-workers']);
}

let testsSucceeded = false;
try {
if (argv.list) {
const tests = await new IntegrationTests(argv.directory).fromCliArgs();
Expand Down Expand Up @@ -99,6 +100,8 @@ async function main() {
verbose: argv.verbose,
updateWorkflow: !argv['disable-update-workflow'],
});
testsSucceeded = success;


if (argv.clean === false) {
logger.warning('Not cleaning up stacks since "--no-clean" was used');
Expand All @@ -125,7 +128,9 @@ async function main() {
if (!runUpdateOnFailed) {
message = 'To re-run failed tests run: yarn integ-runner --update-on-failed';
}
throw new Error(`Some snapshot tests failed!\n${message}`);
if (!testsSucceeded) {
throw new Error(`Some tests failed!\n${message}`);
}
}

}
Expand Down
4 changes: 0 additions & 4 deletions packages/@aws-cdk/integ-runner/lib/runner/runner-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ export abstract class IntegRunner {

protected readonly profile?: string;

protected readonly cdkExecutable: string;

protected _destructiveChanges?: DestructiveChange[];
private legacyContext?: Record<string, any>;

Expand All @@ -153,9 +151,7 @@ export abstract class IntegRunner {
this.sourceFilePath = path.join(this.directory, parsed.base);
this.cdkContextPath = path.join(this.directory, 'cdk.context.json');

this.cdkExecutable = require.resolve('aws-cdk/bin/cdk');
this.cdk = options.cdk ?? new CdkCliWrapper({
cdkExecutable: this.cdkExecutable,
directory: this.directory,
env: {
...options.env,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/integ-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@aws-cdk/integ-runner",
"description": "CDK Integration Testing Tool",
"version": "0.0.0",
"private": true,
"private": false,
"main": "lib/index.js",
"types": "lib/index.d.ts",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cdk-cli-wrapper/lib/cdk-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class CdkCliWrapper implements ICdk {
this.directory = options.directory;
this.env = options.env;
try {
this.cdk = options.cdkExecutable ?? require.resolve('aws-cdk/bin/cdk');
this.cdk = options.cdkExecutable ?? 'cdk';
} catch (e) {
throw new Error(`could not resolve path to cdk executable: "${options.cdkExecutable}"`);
throw new Error(`could not resolve path to cdk executable: "${options.cdkExecutable ?? 'cdk'}"`);
}
}

Expand Down
24 changes: 12 additions & 12 deletions packages/cdk-cli-wrapper/test/cdk-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('default deploy', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['deploy', '--app', 'node bin/my-app.js', 'test-stack1'],
expect.objectContaining({
env: expect.anything(),
Expand Down Expand Up @@ -86,7 +86,7 @@ test('deploy with all arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
expect.arrayContaining([
'deploy',
'--no-strict',
Expand Down Expand Up @@ -146,7 +146,7 @@ test('can parse boolean arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
[
'deploy',
'--app',
Expand Down Expand Up @@ -179,7 +179,7 @@ test('can parse parameters', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
[
'deploy',
'--parameters', 'myparam=test',
Expand Down Expand Up @@ -211,7 +211,7 @@ test('can parse context', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
[
'deploy',
'--app',
Expand Down Expand Up @@ -243,7 +243,7 @@ test('can parse array arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
[
'deploy',
'--notification-arns', 'arn:aws:us-east-1:1111111111:some:resource',
Expand Down Expand Up @@ -274,7 +274,7 @@ test('can provide additional environment', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['deploy', '--app', 'node bin/my-app.js', 'test-stack1'],
expect.objectContaining({
env: expect.objectContaining({
Expand All @@ -300,7 +300,7 @@ test('default synth', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['synth', '--app', 'node bin/my-app.js', 'test-stack1'],
expect.objectContaining({
env: expect.objectContaining({
Expand All @@ -326,7 +326,7 @@ test('synth arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['destroy', '--app', 'node bin/my-app.js', 'test-stack1'],
expect.objectContaining({
env: expect.objectContaining({
Expand Down Expand Up @@ -354,7 +354,7 @@ test('destroy arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['destroy', '--force', '--no-exclusively', '--app', 'node bin/my-app.js', 'test-stack1'],
expect.objectContaining({
env: expect.objectContaining({
Expand All @@ -380,7 +380,7 @@ test('default ls', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['ls', '--app', 'node bin/my-app.js', '*'],
expect.objectContaining({
env: expect.objectContaining({
Expand Down Expand Up @@ -415,7 +415,7 @@ test('ls arguments', () => {

// THEN
expect(spawnSyncMock).toHaveBeenCalledWith(
expect.stringMatching(/aws-cdk\/bin\/cdk/),
expect.stringMatching(/cdk/),
['ls', '--long', '--app', 'node bin/my-app.js', '*'],
expect.objectContaining({
env: expect.objectContaining({
Expand Down

0 comments on commit 3635050

Please sign in to comment.