/
assertions.ts
70 lines (61 loc) · 1.96 KB
/
assertions.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
import { CustomResource, CfnOutput } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ExpectedResult, ActualResult } from './common';
import { AssertionRequest, AssertionsProvider, ASSERT_RESOURCE_TYPE } from './providers';
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct as CoreConstruct } from '@aws-cdk/core';
/**
* Options for an EqualsAssertion
*/
export interface EqualsAssertionProps {
/**
* The actual results to compare
*/
readonly actual: ActualResult;
/**
* The expected result to assert
*/
readonly expected: ExpectedResult;
/**
* Set this to true if a failed assertion should
* result in a CloudFormation deployment failure
*
* This is only necessary if assertions are being
* executed outside of `integ-runner`.
*
* @default false
*/
readonly failDeployment?: boolean;
}
/**
* Construct that creates a CustomResource to assert that two
* values are equal
*/
export class EqualsAssertion extends CoreConstruct {
/**
* The result of the assertion
*/
public readonly result: string;
constructor(scope: Construct, id: string, props: EqualsAssertionProps) {
super(scope, id);
const assertionProvider = new AssertionsProvider(this, 'AssertionProvider');
const properties: AssertionRequest = {
actual: props.actual.result,
expected: props.expected.result,
failDeployment: props.failDeployment,
};
const resource = new CustomResource(this, 'Default', {
serviceToken: assertionProvider.serviceToken,
properties: {
...properties,
salt: Date.now().toString(), // always update,
},
resourceType: ASSERT_RESOURCE_TYPE,
});
this.result = resource.getAttString('data');
new CfnOutput(this, 'AssertionResults', {
value: this.result,
}).overrideLogicalId(`AssertionResults${id}`);
}
}