Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integ-runner): publish integ-runner cli #20477

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 2 additions & 6 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 @@ -146,16 +144,14 @@ export abstract class IntegRunner {
this.testName = testName;
} else {
const relativePath = path.relative(options.directory, parsed.dir);
this.testName = `${relativePath ? relativePath+'/' : ''}${parsed.name}`;
this.testName = `${relativePath ? relativePath + '/' : ''}${parsed.name}`;
}
this.snapshotDir = path.join(this.directory, `${testName}.integ.snapshot`);
this.relativeSnapshotDir = `${testName}.integ.snapshot`;
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 Expand Up @@ -371,7 +367,7 @@ export abstract class IntegRunner {
}

protected getContext(additionalContext?: Record<string, any>): Record<string, any> {
const futureFlags: {[key: string]: any} = {};
const futureFlags: { [key: string]: any } = {};
Object.entries(FUTURE_FLAGS)
.filter(([k, _]) => !FUTURE_FLAGS_EXPIRED.includes(k))
.forEach(([k, v]) => futureFlags[k] = v);
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