Skip to content

Commit

Permalink
Merge branch 'master' into fix-multi-login
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored May 18, 2022
2 parents cfc2eb1 + f7732a1 commit 4d3f234
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 331 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { IVpcEndpoint } from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack } from '@aws-cdk/core';
import { ArnFormat, CfnOutput, IResource as IResourceBase, Resource, Stack, Token } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ApiDefinition } from './api-definition';
import { ApiKey, ApiKeyOptions, IApiKey } from './api-key';
Expand Down Expand Up @@ -368,7 +368,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
}

public arnForExecuteApi(method: string = '*', path: string = '/*', stage: string = '*') {
if (!path.startsWith('/')) {
if (!Token.isUnresolved(path) && !path.startsWith('/')) {
throw new Error(`"path" must begin with a "/": '${path}'`);
}

Expand Down
12 changes: 11 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/restapi.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Template } from '@aws-cdk/assertions';
import { GatewayVpcEndpoint } from '@aws-cdk/aws-ec2';
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
import { App, CfnElement, CfnResource, Stack } from '@aws-cdk/core';
import { App, CfnElement, CfnResource, Lazy, Stack } from '@aws-cdk/core';
import * as apigw from '../lib';

describe('restapi', () => {
Expand Down Expand Up @@ -424,6 +424,16 @@ describe('restapi', () => {
expect(() => api.arnForExecuteApi('method', 'hey-path', 'stage')).toThrow(/"path" must begin with a "\/": 'hey-path'/);
});

test('"executeApiArn" path can be a token', () => {
// GIVEN
const stack = new Stack();
const api = new apigw.RestApi(stack, 'api');
api.root.addMethod('GET');

// THEN
expect(() => api.arnForExecuteApi('method', Lazy.string(({ produce: () => 'path' })), 'stage')).not.toThrow();
});

test('"executeApiArn" will convert ANY to "*"', () => {
// GIVEN
const stack = new Stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25249,7 +25249,7 @@
"KafkaClusterEncryptionInTransit": "Details of encryption in transit to the Apache Kafka cluster.",
"KafkaConnectVersion": "The version of Kafka Connect. It has to be compatible with both the Apache Kafka cluster's version and the plugins.",
"LogDelivery": "The settings for delivering connector logs to Amazon CloudWatch Logs.",
"Plugins": "Specifies which plugins were used for this connector.",
"Plugins": "Specifies which plugin to use for the connector. You must specify a single-element list. Amazon MSK Connect does not currently support specifying multiple plugins.",
"ServiceExecutionRoleArn": "The Amazon Resource Name (ARN) of the IAM role used by the connector to access Amazon Web Services resources.",
"WorkerConfiguration": "The worker configurations that are in use with the connector."
}
Expand Down
76 changes: 42 additions & 34 deletions packages/@aws-cdk/integ-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ new IntegTest(app, 'Integ', { testCases: [stackUnderTest, testCaseWithAssets] })

This library also provides a utility to make assertions against the infrastructure that the integration test deploys.

The easiest way to do this is to create a `TestCase` and then access the `DeployAssert` that is automatically created.
There are two main scenarios in which assertions are created.

- Part of an integration test using `integ-runner`

In this case you would create an integration test using the `IntegTest` construct and then make assertions using the `assert` property.
You should **not** utilize the assertion constructs directly, but should instead use the `methods` on `IntegTest.assert`.

```ts
declare const app: App;
Expand All @@ -187,31 +192,35 @@ const integ = new IntegTest(app, 'Integ', { testCases: [stack] });
integ.assert.awsApiCall('S3', 'getObject');
```

### DeployAssert

Assertions are created by using the `DeployAssert` construct. This construct creates it's own `Stack` separate from
any stacks that you create as part of your integration tests. This `Stack` is treated differently from other stacks
by the `integ-runner` tool. For example, this stack will not be diffed by the `integ-runner`.
- Part of a normal CDK deployment

Any assertions that you create should be created in the scope of `DeployAssert`. For example,
In this case you may be using assertions as part of a normal CDK deployment in order to make an assertion on the infrastructure
before the deployment is considered successful. In this case you can utilize the assertions constructs directly.

```ts
declare const app: App;
declare const myAppStack: Stack;

const assert = new DeployAssert(app);
new AwsApiCall(assert, 'GetObject', {
new AwsApiCall(myAppStack, 'GetObject', {
service: 'S3',
api: 'getObject',
});
```

### DeployAssert

Assertions are created by using the `DeployAssert` construct. This construct creates it's own `Stack` separate from
any stacks that you create as part of your integration tests. This `Stack` is treated differently from other stacks
by the `integ-runner` tool. For example, this stack will not be diffed by the `integ-runner`.

`DeployAssert` also provides utilities to register your own assertions.

```ts
declare const myCustomResource: CustomResource;
declare const stack: Stack;
declare const app: App;
const assert = new DeployAssert(app);
assert.assert(

const integ = new IntegTest(app, 'Integ', { testCases: [stack] });
integ.assert.assert(
'CustomAssertion',
ExpectedResult.objectLike({ foo: 'bar' }),
ActualResult.fromCustomResource(myCustomResource, 'data'),
Expand All @@ -228,12 +237,12 @@ AWS API call to receive some data. This library does this by utilizing CloudForm
which means that CloudFormation will call out to a Lambda Function which will
use the AWS JavaScript SDK to make the API call.

This can be done by using the class directory:
This can be done by using the class directory (in the case of a normal deployment):

```ts
declare const assert: DeployAssert;
declare const stack: Stack;

new AwsApiCall(assert, 'MyAssertion', {
new AwsApiCall(stack, 'MyAssertion', {
service: 'SQS',
api: 'receiveMessage',
parameters: {
Expand All @@ -242,12 +251,15 @@ new AwsApiCall(assert, 'MyAssertion', {
});
```

Or by using the `awsApiCall` method on `DeployAssert`:
Or by using the `awsApiCall` method on `DeployAssert` (when writing integration tests):

```ts
declare const app: App;
const assert = new DeployAssert(app);
assert.awsApiCall('SQS', 'receiveMessage', {
declare const stack: Stack;
const integ = new IntegTest(app, 'Integ', {
testCases: [stack],
});
integ.assert.awsApiCall('SQS', 'receiveMessage', {
QueueUrl: 'url',
});
```
Expand Down Expand Up @@ -281,21 +293,18 @@ const message = integ.assert.awsApiCall('SQS', 'receiveMessage', {
WaitTimeSeconds: 20,
});

new EqualsAssertion(integ.assert, 'ReceiveMessage', {
actual: ActualResult.fromAwsApiCall(message, 'Messages.0.Body'),
expected: ExpectedResult.objectLike({
requestContext: {
condition: 'Success',
},
requestPayload: {
status: 'OK',
},
responseContext: {
statusCode: 200,
},
responsePayload: 'success',
}),
});
message.assertAtPath('Messages.0.Body', ExpectedResult.objectLike({
requestContext: {
condition: 'Success',
},
requestPayload: {
status: 'OK',
},
responseContext: {
statusCode: 200,
},
responsePayload: 'success',
}));
```

#### Match
Expand All @@ -305,7 +314,6 @@ can be used to construct the `ExpectedResult`.

```ts
declare const message: AwsApiCall;
declare const assert: DeployAssert;

message.assert(ExpectedResult.objectLike({
Messages: Match.arrayWith([
Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/integ-tests/lib/assertions/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CustomResource } from '@aws-cdk/core';
import { AwsApiCall } from './sdk';
import { IAwsApiCall } from './sdk';

/**
* Represents the "actual" results to compare
*/
Expand All @@ -16,7 +17,7 @@ export abstract class ActualResult {
/**
* Get the actual results from a AwsApiCall
*/
public static fromAwsApiCall(query: AwsApiCall, attribute: string): ActualResult {
public static fromAwsApiCall(query: IAwsApiCall, attribute: string): ActualResult {
return {
result: query.getAttString(attribute),
};
Expand Down
128 changes: 0 additions & 128 deletions packages/@aws-cdk/integ-tests/lib/assertions/deploy-assert.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/integ-tests/lib/assertions/index.ts
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';
Loading

0 comments on commit 4d3f234

Please sign in to comment.