forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(integ-tests): DeployAssert should be private (aws#20382)
The `DeployAssert` construct is really an implementation detail that is only used when making assertions as part of integration tests. This PR makes the construct private and creates a public interface (`IDeployAssert`). This PR also: - Removes the scope swap since we no longer need to pass around `DeployAssert`. - Removes some unused code (ResultsCollector). ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
14 changed files
with
306 additions
and
327 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
128 changes: 0 additions & 128 deletions
128
packages/@aws-cdk/integ-tests/lib/assertions/deploy-assert.ts
This file was deleted.
Oops, something went wrong.
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,6 +1,6 @@ | ||
export * from './assertions'; | ||
export * from './types'; | ||
export * from './sdk'; | ||
export * from './deploy-assert'; | ||
export * from './assertions'; | ||
export * from './providers'; | ||
export * from './common'; | ||
export * from './match'; |
76 changes: 76 additions & 0 deletions
76
packages/@aws-cdk/integ-tests/lib/assertions/private/deploy-assert.ts
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,76 @@ | ||
import { Stack } from '@aws-cdk/core'; | ||
import { Construct, IConstruct, Node } from 'constructs'; | ||
import { EqualsAssertion } from '../assertions'; | ||
import { ExpectedResult, ActualResult } from '../common'; | ||
import { md5hash } from '../private/hash'; | ||
import { AwsApiCall, LambdaInvokeFunction, IAwsApiCall, LambdaInvokeFunctionProps } from '../sdk'; | ||
import { IDeployAssert } from '../types'; | ||
|
||
|
||
const DEPLOY_ASSERT_SYMBOL = Symbol.for('@aws-cdk/integ-tests.DeployAssert'); | ||
|
||
|
||
// 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 DeployAssert | ||
*/ | ||
export interface DeployAssertProps { } | ||
|
||
/** | ||
* Construct that allows for registering a list of assertions | ||
* that should be performed on a construct | ||
*/ | ||
export class DeployAssert extends CoreConstruct implements IDeployAssert { | ||
|
||
/** | ||
* Returns whether the construct is a DeployAssert construct | ||
*/ | ||
public static isDeployAssert(x: any): x is DeployAssert { | ||
return x !== null && typeof(x) === 'object' && DEPLOY_ASSERT_SYMBOL in x; | ||
} | ||
|
||
/** | ||
* Finds a DeployAssert construct in the given scope | ||
*/ | ||
public static of(construct: IConstruct): DeployAssert { | ||
const scopes = Node.of(Node.of(construct).root).findAll(); | ||
const deployAssert = scopes.find(s => DeployAssert.isDeployAssert(s)); | ||
if (!deployAssert) { | ||
throw new Error('No DeployAssert construct found in scopes'); | ||
} | ||
return deployAssert as DeployAssert; | ||
} | ||
|
||
public scope: Stack; | ||
|
||
constructor(scope: Construct) { | ||
super(scope, 'Default'); | ||
|
||
this.scope = new Stack(scope, 'DeployAssert'); | ||
|
||
Object.defineProperty(this, DEPLOY_ASSERT_SYMBOL, { value: true }); | ||
} | ||
|
||
public awsApiCall(service: string, api: string, parameters?: any): IAwsApiCall { | ||
return new AwsApiCall(this.scope, `AwsApiCall${service}${api}`, { | ||
api, | ||
service, | ||
parameters, | ||
}); | ||
} | ||
|
||
public invokeFunction(props: LambdaInvokeFunctionProps): IAwsApiCall { | ||
const hash = md5hash(this.scope.resolve(props)); | ||
return new LambdaInvokeFunction(this.scope, `LambdaInvoke${hash}`, props); | ||
} | ||
|
||
public assert(id: string, expected: ExpectedResult, actual: ActualResult): void { | ||
new EqualsAssertion(this.scope, `EqualsAssertion${id}`, { | ||
expected, | ||
actual, | ||
}); | ||
} | ||
} |
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
12 changes: 0 additions & 12 deletions
12
packages/@aws-cdk/integ-tests/lib/assertions/providers/lambda-handler/results.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.