-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from guardian/aa-apply-app-tag
fix: Improve GuAutoScalingGroup's support of a multi-app stack
- Loading branch information
Showing
5 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { SynthUtils } from "@aws-cdk/assert"; | ||
import type { GuStack } from "../../constructs/core"; | ||
import type { SynthedStack } from "./synthed-stack"; | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace -- custom Jest matcher | ||
namespace jest { | ||
interface Matchers<R> { | ||
toHaveResourceOfTypeAndLogicalId(resourceType: string, logicalId: string | RegExp): R; | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ | ||
/** | ||
* A helper function to assert a stack has a resource of a particular type and logicalId. | ||
* Useful for when the logicalId is auto-generated. | ||
* @param stack the stack to make an assertion on | ||
* @param resourceType the AWS resource type string, for example "AWS::AutoScaling::AutoScalingGroup" | ||
* @param logicalId a string or regex pattern to match against the resource's logicalId | ||
*/ | ||
toHaveResourceOfTypeAndLogicalId(stack: GuStack, resourceType: string, logicalId: string | RegExp) { | ||
const json = SynthUtils.toCloudFormation(stack) as SynthedStack; | ||
|
||
const matchResult = Object.entries(json.Resources).find(([key, { Type }]) => { | ||
const logicalIdMatch = logicalId instanceof RegExp ? logicalId.test(key) : key === logicalId; | ||
const typeMatch = Type === resourceType; | ||
return logicalIdMatch && typeMatch; | ||
}); | ||
|
||
return matchResult | ||
? { | ||
pass: true, | ||
message: () => "", | ||
} | ||
: { | ||
pass: false, | ||
message: () => `No resource found matching logicalId ${logicalId.toString()} and Type ${resourceType}`, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
import type { Stage } from "../../constants"; | ||
|
||
interface Parameter { | ||
Type: string; | ||
Description: string; | ||
Default?: string | number; | ||
AllowedValues?: Array<string | number>; | ||
} | ||
|
||
type ResourceProperty = Record<string, unknown>; | ||
type Resource = Record<string, { Type: string; Properties: ResourceProperty }>; | ||
|
||
export interface SynthedStack { | ||
Parameters: Record<string, { Properties: Record<string, unknown> }>; | ||
Mappings: Record<string, unknown>; | ||
Resources: Record<string, { Properties: Record<string, unknown> }>; | ||
Parameters: Record<string, Parameter>; | ||
Mappings: Record<Stage, unknown>; | ||
Resources: Resource; | ||
} |