generated from szikszail/npm-package
/
custom.ts
64 lines (59 loc) · 2.23 KB
/
custom.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
import { Match } from "aws-cdk-lib/assertions";
import { AdvancedTemplate } from "./advanced-template";
import { Resource, RemovableResource } from "./resource";
/**
* A test construct for the CustomResource resource type
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.CfnCustomResource.html}
*/
export class CustomResource extends RemovableResource {
constructor(template: AdvancedTemplate, props?: any) {
super('Custom::AWS', template, props);
}
/**
* Sets a matching event handler for the custom resource
* @param event The matching event name (exact match)
* @param action The matching action name (exact match)
* @param service The matching service name (exact match)
* @param parameters Optional parameters of the custom resource
* @returns
*/
public withEventHandler(event: string, action: string, service: string, parameters?: any) {
const handler: any = {
action, service,
};
if (parameters) {
handler.parameters = Match.objectLike(parameters);
}
this.withProperty(event, Match.serializedJson(Match.objectLike(handler)));
return this;
}
/**
* Sets a matching "Create" event handler for the custom resource
* @param action The matching action name (exact match)
* @param service The matching service name (exact match)
* @param parameters Optional parameters of the custom resource
* @returns
*/
public withCreateHandler(action: string, service: string, parameters?: any) {
return this.withEventHandler('Create', action, service, parameters);
}
/**
* Sets a matching "Update" event handler for the custom resource
* @param action The matching action name (exact match)
* @param service The matching service name (exact match)
* @param parameters Optional parameters of the custom resource
* @returns
*/
public withUpdateHandler(action: string, service: string, parameters?: any) {
return this.withEventHandler('Update', action, service, parameters);
}
/**
* Sets a matching service token to the resource passed
* @param resource The test construct to connect
* @returns
*/
public withServiceToken(resource: Resource) {
this.withProperty('ServiceToken', resource.arn);
return this;
}
}