Skip to content

Commit

Permalink
chore: introduce pragma:context to cdk-integ (aws#15779)
Browse files Browse the repository at this point in the history
Since context passed via command line overrides the App context, setting newStyleSynthesis in the pipeline integration tests will not work since in the v2 branch we set newStyleSynth to “false” explicitly in cdk-integ.

Introduce a new cdk-integ pragma that can be used to override this context and use it for pipelines integration tests.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Elad Ben-Israel authored and hollanddd committed Aug 26, 2021
1 parent 8c08c69 commit 8118293
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/pipelines/test/integ.newpipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
/// !cdk-integ PipelineStack
/// !cdk-integ PipelineStack pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true
import * as sqs from '@aws-cdk/aws-sqs';
import { App, Stack, StackProps, Stage, StageProps } from '@aws-cdk/core';
import { Construct } from 'constructs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// !cdk-integ PipelineSecurityStack
/// !cdk-integ PipelineSecurityStack pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import * as iam from '@aws-cdk/aws-iam';
Expand Down
16 changes: 15 additions & 1 deletion tools/cdk-integ-tools/lib/integ-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CDK_OUTDIR = 'cdk-integ.out';

const CDK_INTEG_STACK_PRAGMA = '/// !cdk-integ';
const PRAGMA_PREFIX = 'pragma:';
const SET_CONTEXT_PRAGMA_PREFIX = 'pragma:set-context:';

export class IntegrationTests {
constructor(private readonly directory: string) {
Expand Down Expand Up @@ -95,10 +96,23 @@ export class IntegrationTest {
* Return the "main" template or a concatenation of all listed templates in the pragma
*/
public async cdkSynthFast(options: SynthOptions = {}): Promise<any> {
const context = {
const context: Record<string, string> = {
...options.context,
};

// apply context from set-context pragma
// usage: pragma:set-context:key=value
const ctxPragmas = (await this.pragmas()).filter(p => p.startsWith(SET_CONTEXT_PRAGMA_PREFIX));
for (const p of ctxPragmas) {
const instruction = p.substring(SET_CONTEXT_PRAGMA_PREFIX.length);
const [key, value] = instruction.split('=');
if (key == null || value == null) {
throw new Error(`invalid "set-context" pragma syntax. example: "pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true" got: ${p}`);
}

context[key] = value;
}

try {
await exec(['node', `${this.name}`], {
cwd: this.directory,
Expand Down

0 comments on commit 8118293

Please sign in to comment.