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

Feature request: enable feature flags when running tests #18535

Closed
1 of 2 tasks
jfly opened this issue Jan 19, 2022 · 2 comments
Closed
1 of 2 tasks

Feature request: enable feature flags when running tests #18535

jfly opened this issue Jan 19, 2022 · 2 comments
Assignees
Labels
@aws-cdk/aws-kms Related to AWS Key Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@jfly
Copy link

jfly commented Jan 19, 2022

Description

Right now, feature flags in cdk.json take effect when inside of a cdk synth, but are not picked up when in tests. @nija-at says that this is intentional.

Use Case

I don't think this is a very sane default for users of cdk: I can totally see why people working on cdk would not want feature flags to automagically get enabled in tests, but IMO that's not appropriate behavior for users of cdk. For example, we recently started getting warnings like this when running cdk synth:

[WARNING] @aws-cdk/aws-kms.KeyProps#trustAccountIdentities is deprecated.
redundant with the @aws-cdk/aws-kms:defaultKeyPolicies feature flag
This API will be removed in the next major release.

This felt pretty silly to us, because even though we had the @aws-cdk/aws-kms:defaultKeyPolicies enabled in our cdk.json file, we could not remove this trustAccountIdentities parameter without breaking tests.

Proposed Solution

I'd love to see cdk.json feature flags handled the same way between cdk synth and unittests.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@jfly jfly added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 19, 2022
@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Jan 19, 2022
@njlynch njlynch added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2022
@njlynch
Copy link
Contributor

njlynch commented Jan 21, 2022

When invoking the cdk CLI, the CLI itself takes care of loading the cdk.json file and parsing out the context; however, it's difficult to provide a one-size-fits-all solution to enable that context while running inside any given test runner in all of the languages we support.

That being said, the solution in any given language + test runner is fairly trivial; you simply need to pass the context from cdk.json and pass it into your App creation. Here's an example for Typescript + Jest:

let app: cdk.App;
let context: { [key: string]: any };
beforeAll(async () => { context = JSON.parse((await fs.readFile('cdk.json', 'utf8'))).context; });
beforeEach(() => { app = new cdk.App({ context }); });

I hope that helps.

@njlynch njlynch closed this as completed Jan 21, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-kms Related to AWS Key Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

2 participants