Skip to content

Commit 7c41e69

Browse files
authored
Merge branch 'master' into huijbers/config-tests
2 parents a05fe49 + 2628cb5 commit 7c41e69

File tree

183 files changed

+2992
-2301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+2992
-2301
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -803,35 +803,17 @@ The pattern is simple:
803803
with the name of the context key that **enables** this new feature (for
804804
example, `ENABLE_STACK_NAME_DUPLICATES`). The context key should be in the
805805
form `module.Type:feature` (e.g. `@aws-cdk/core:enableStackNameDuplicates`).
806-
2. Use `node.tryGetContext(cxapi.ENABLE_XXX)` to check if this feature is enabled
806+
2. Use `FeatureFlags.of(construct).isEnabled(cxapi.ENABLE_XXX)` to check if this feature is enabled
807807
in your code. If it is not defined, revert to the legacy behavior.
808808
3. Add your feature flag to the `FUTURE_FLAGS` map in
809809
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts).
810810
This map is inserted to generated `cdk.json` files for new projects created
811811
through `cdk init`.
812-
4. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:
812+
4. In your tests, use the `testFutureBehavior` and `testLegacyBehavior` [jest helper methods] to test the enabled and disabled behavior.
813+
5. In your PR title (which goes into CHANGELOG), add a `(under feature flag)` suffix. e.g:
813814

814815
`fix(core): impossible to use the same physical stack name for two stacks (under feature flag)`
815816

816-
In the [next major version of the
817-
CDK](https://github.com/aws/aws-cdk/issues/3398) we will either remove the
818-
legacy behavior or flip the logic for all these features and then
819-
reset the `FEATURE_FLAGS` map for the next cycle.
820-
821-
### Feature Flags - CDKv2
822-
823-
We have started working on the next version of the CDK, specifically CDKv2. This is currently being maintained
824-
on a separate branch `v2-main` whereas `master` continues to track versions `1.x`.
825-
826-
Feature flags introduced in the CDK 1.x and removed in 2.x, must be added to the `FUTURE_FLAGS_EXPIRED` list in
827-
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cx-api/lib/features.ts)
828-
on the `v2-main` branch.
829-
This will make the default behaviour in CDKv2 as if the flag is enabled and also prevents users from disabling
830-
the feature flag.
831-
832-
A couple of [jest helper methods] are available for use with unit tests. These help run unit tests that test
833-
behaviour when flags are enabled or disabled in the two major versions.
834-
835817
[jest helper methods]: https://github.com/aws/aws-cdk/blob/master/tools/@aws-cdk/cdk-build-tools/lib/feature-flag.ts
836818

837819
## Versioning and Release

allowed-breaking-changes.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,14 @@ removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.retry
115115
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.tumblingWindow
116116
base-types:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps
117117
base-types:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps
118-
base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps
118+
base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps
119+
120+
# fixed vpc property of BaseLoadBalancer so it correctly implements I(Application|Network)LoadBalancer (i.e: must be optional)
121+
changed-type:@aws-cdk/aws-elasticloadbalancingv2.ApplicationLoadBalancer.vpc
122+
changed-type:@aws-cdk/aws-elasticloadbalancingv2.BaseLoadBalancer.vpc
123+
changed-type:@aws-cdk/aws-elasticloadbalancingv2.NetworkLoadBalancer.vpc
124+
125+
# removed methods and properties related to event bridge notifications for S3 buckets as they are not yet supported (19 Jan 2022)
126+
removed:@aws-cdk/aws-s3.Bucket.enableEventBridgeNotification
127+
removed:@aws-cdk/aws-s3.BucketBase.enableEventBridgeNotification
128+
removed:@aws-cdk/aws-s3.BucketProps.eventBridgeEnabled

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@yarnpkg/lockfile": "^1.1.0",
19-
"cdk-generate-synthetic-examples": "^0.1.2",
19+
"cdk-generate-synthetic-examples": "^0.1.3",
2020
"conventional-changelog-cli": "^2.2.2",
2121
"fs-extra": "^9.1.0",
2222
"graceful-fs": "^4.2.9",

packages/@aws-cdk/assert-internal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@aws-cdk/pkglint": "0.0.0",
2929
"@types/jest": "^27.4.0",
3030
"jest": "^27.4.7",
31-
"ts-jest": "^27.1.2"
31+
"ts-jest": "^27.1.3"
3232
},
3333
"dependencies": {
3434
"@aws-cdk/cloud-assembly-schema": "0.0.0",

packages/@aws-cdk/assert/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"aws-cdk-migration": "0.0.0",
4242
"constructs": "^3.3.69",
4343
"jest": "^27.3.1",
44-
"ts-jest": "^27.1.2"
44+
"ts-jest": "^27.1.3"
4545
},
4646
"dependencies": {
4747
"@aws-cdk/cloudformation-diff": "0.0.0",

packages/@aws-cdk/assertions/lib/match.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class LiteralMatch extends Matcher {
115115

116116
public test(actual: any): MatchResult {
117117
if (Array.isArray(this.pattern)) {
118-
return new ArrayMatch(this.name, this.pattern, { subsequence: false }).test(actual);
118+
return new ArrayMatch(this.name, this.pattern, { subsequence: false, partialObjects: this.partialObjects }).test(actual);
119119
}
120120

121121
if (typeof this.pattern === 'object') {
@@ -155,13 +155,21 @@ interface ArrayMatchOptions {
155155
* @default true
156156
*/
157157
readonly subsequence?: boolean;
158+
159+
/**
160+
* Whether to continue matching objects inside the array partially
161+
*
162+
* @default false
163+
*/
164+
readonly partialObjects?: boolean;
158165
}
159166

160167
/**
161168
* Match class that matches arrays.
162169
*/
163170
class ArrayMatch extends Matcher {
164171
private readonly subsequence: boolean;
172+
private readonly partialObjects: boolean;
165173

166174
constructor(
167175
public readonly name: string,
@@ -170,6 +178,7 @@ class ArrayMatch extends Matcher {
170178

171179
super();
172180
this.subsequence = options.subsequence ?? true;
181+
this.partialObjects = options.partialObjects ?? false;
173182
}
174183

175184
public test(actual: any): MatchResult {
@@ -195,7 +204,10 @@ class ArrayMatch extends Matcher {
195204
while (patternIdx < this.pattern.length && actualIdx < actual.length) {
196205
const patternElement = this.pattern[patternIdx];
197206

198-
const matcher = Matcher.isMatcher(patternElement) ? patternElement : new LiteralMatch(this.name, patternElement);
207+
const matcher = Matcher.isMatcher(patternElement)
208+
? patternElement
209+
: new LiteralMatch(this.name, patternElement, { partialObjects: this.partialObjects });
210+
199211
const matcherName = matcher.name;
200212
if (this.subsequence && (matcherName == 'absent' || matcherName == 'anyValue')) {
201213
// array subsequence matcher is not compatible with anyValue() or absent() matcher. They don't make sense to be used together.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { filterLogicalId, formatFailure, matchSection } from './section';
2+
import { Template } from './template';
3+
4+
export function findParameters(template: Template, logicalId: string, props: any = {}): { [key: string]: { [key: string]: any } } {
5+
const section: { [key: string] : {} } = template.Parameters;
6+
const result = matchSection(filterLogicalId(section, logicalId), props);
7+
8+
if (!result.match) {
9+
return {};
10+
}
11+
12+
return result.matches;
13+
}
14+
15+
export function hasParameter(template: Template, logicalId: string, props: any): string | void {
16+
const section: { [key: string] : {} } = template.Parameters;
17+
const result = matchSection(filterLogicalId(section, logicalId), props);
18+
if (result.match) {
19+
return;
20+
}
21+
22+
if (result.closestResult === undefined) {
23+
return 'No parameters found in the template';
24+
}
25+
26+
return [
27+
`Template has ${result.analyzedCount} parameters, but none match as expected.`,
28+
formatFailure(result.closestResult),
29+
].join('\n');
30+
}

packages/@aws-cdk/assertions/lib/private/template.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
export type Template = {
44
Resources: { [logicalId: string]: Resource },
55
Outputs: { [logicalId: string]: Output },
6-
Mappings: { [logicalId: string]: Mapping }
6+
Mappings: { [logicalId: string]: Mapping },
7+
Parameters: { [logicalId: string]: Parameter }
78
}
89

910
export type Resource = {
@@ -13,4 +14,9 @@ export type Resource = {
1314

1415
export type Output = { [key: string]: any };
1516

16-
export type Mapping = { [key: string]: any };
17+
export type Mapping = { [key: string]: any };
18+
19+
export type Parameter = {
20+
Type: string;
21+
[key: string]: any;
22+
}

packages/@aws-cdk/assertions/lib/template.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Match } from './match';
55
import { Matcher } from './matcher';
66
import { findMappings, hasMapping } from './private/mappings';
77
import { findOutputs, hasOutput } from './private/outputs';
8+
import { findParameters, hasParameter } from './private/parameters';
89
import { countResources, findResources, hasResource, hasResourceProperties } from './private/resources';
910
import { Template as TemplateType } from './private/template';
1011

@@ -108,6 +109,30 @@ export class Template {
108109
return findResources(this.template, type, props);
109110
}
110111

112+
/**
113+
* Assert that a Parameter with the given properties exists in the CloudFormation template.
114+
* By default, performs partial matching on the parameter, via the `Match.objectLike()`.
115+
* To configure different behavior, use other matchers in the `Match` class.
116+
* @param logicalId the name of the parameter. Provide `'*'` to match all parameters in the template.
117+
* @param props the parameter as should be expected in the template.
118+
*/
119+
public hasParameter(logicalId: string, props: any): void {
120+
const matchError = hasParameter(this.template, logicalId, props);
121+
if (matchError) {
122+
throw new Error(matchError);
123+
}
124+
}
125+
126+
/**
127+
* Get the set of matching Parameters that match the given properties in the CloudFormation template.
128+
* @param logicalId the name of the parameter. Provide `'*'` to match all parameters in the template.
129+
* @param props by default, matches all Parameters in the template.
130+
* When a literal object is provided, performs a partial match via `Match.objectLike()`.
131+
* Use the `Match` APIs to configure a different behaviour. */
132+
public findParameters(logicalId: string, props: any = {}): { [key: string]: { [key: string]: any } } {
133+
return findParameters(this.template, logicalId, props);
134+
}
135+
111136
/**
112137
* Assert that an Output with the given properties exists in the CloudFormation template.
113138
* By default, performs partial matching on the resource, via the `Match.objectLike()`.

packages/@aws-cdk/assertions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@types/jest": "^27.4.0",
6969
"constructs": "^3.3.69",
7070
"jest": "^27.4.7",
71-
"ts-jest": "^27.1.2"
71+
"ts-jest": "^27.1.3"
7272
},
7373
"dependencies": {
7474
"@aws-cdk/cloud-assembly-schema": "0.0.0",

0 commit comments

Comments
 (0)