generated from szikszail/npm-package
/
advanced-matcher.ts
74 lines (67 loc) · 1.93 KB
/
advanced-matcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Match, Matcher } from "aws-cdk-lib/assertions";
import { Resource } from "./resource";
/**
* Matchers to use to assert CloudFormation template.
*/
export class AdvancedMatcher {
/**
* Matches the Fn function with the name and the passed values.
* @param name The name of Fn function
* @param pattern The values matched with Match.arrayWith()
* @returns
*/
public static fn(name: string, ...pattern: any[]): Matcher {
return Match.objectLike({
["Fn::" + name]: Match.arrayWith([...pattern]),
});
}
/**
* Matches a Fn::Select with the passed value.
* @param pattern The value to match with.
* @returns
*/
public static fnSelect(pattern: any): Matcher {
return this.fn('Select', pattern);
}
/**
* Matches a Fn::Split with the passed value.
* @param pattern The value to match with.
* @returns
*/
public static fnSplit(pattern: any): Matcher {
return this.fn('Split', pattern);
}
/**
* Matches a Fn::GetAtt with the passed values.
* @param pattern The values to match with, in order.
* @returns
*/
public static fnGetAtt(...pattern: any[]): Matcher {
return this.fn('GetAtt', ...pattern);
}
/**
* Matches a Fn::Equals with the passed values.
* @param pattern The values to match with, in order.
* @returns
*/
public static fnEquals(...pattern: any[]): Matcher {
return this.fn('Equals', ...pattern);
}
/**
* Matches a Fn::Join with the passed value.
* @param pattern The value to match with.
* @returns
*/
public static fnJoin(pattern: any): Matcher {
return this.fn('Join', pattern);
}
/**
* Matches with the ARN of the test construct.
* @param resource The test construct
* @param attribute The attribute parsed for the ARN defaults to "Arn".
* @returns
*/
public static arn(resource: Resource, attribute?: string): Matcher {
return this.fnGetAtt(resource.id, attribute || "Arn")
}
}