-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apigatewayv2): support for mock integration type (#18129)
resolves #15008 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
a8094c7
commit 7779c14
Showing
6 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-apigatewayv2-integrations/lib/websocket/index.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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './lambda'; | ||
export * from './mock'; |
27 changes: 27 additions & 0 deletions
27
packages/@aws-cdk/aws-apigatewayv2-integrations/lib/websocket/mock.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,27 @@ | ||
import { | ||
WebSocketRouteIntegration, | ||
WebSocketIntegrationType, | ||
WebSocketRouteIntegrationConfig, | ||
WebSocketRouteIntegrationBindOptions, | ||
} from '@aws-cdk/aws-apigatewayv2'; | ||
|
||
/** | ||
* Mock WebSocket Integration | ||
*/ | ||
export class WebSocketMockIntegration extends WebSocketRouteIntegration { | ||
|
||
/** | ||
* @param id id of the underlying integration construct | ||
*/ | ||
constructor(id: string) { | ||
super(id); | ||
} | ||
|
||
bind(options: WebSocketRouteIntegrationBindOptions): WebSocketRouteIntegrationConfig { | ||
options; | ||
return { | ||
type: WebSocketIntegrationType.MOCK, | ||
uri: '', | ||
}; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
packages/@aws-cdk/aws-apigatewayv2-integrations/test/websocket/integ.mock.expected.json
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,108 @@ | ||
{ | ||
"Resources": { | ||
"mywsapi32E6CE11": { | ||
"Type": "AWS::ApiGatewayV2::Api", | ||
"Properties": { | ||
"Name": "mywsapi", | ||
"ProtocolType": "WEBSOCKET", | ||
"RouteSelectionExpression": "$request.body.action" | ||
} | ||
}, | ||
"mywsapidefaultRouteDefaultIntegrationFFCB3BA9": { | ||
"Type": "AWS::ApiGatewayV2::Integration", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
"IntegrationType": "MOCK", | ||
"IntegrationUri": "" | ||
} | ||
}, | ||
"mywsapidefaultRouteE9382DF8": { | ||
"Type": "AWS::ApiGatewayV2::Route", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
"RouteKey": "$default", | ||
"AuthorizationType": "NONE", | ||
"Target": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"integrations/", | ||
{ | ||
"Ref": "mywsapidefaultRouteDefaultIntegrationFFCB3BA9" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
}, | ||
"mywsapisendmessageRouteSendMessageIntegrationD29E12F9": { | ||
"Type": "AWS::ApiGatewayV2::Integration", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
"IntegrationType": "MOCK", | ||
"IntegrationUri": "" | ||
} | ||
}, | ||
"mywsapisendmessageRouteAE873328": { | ||
"Type": "AWS::ApiGatewayV2::Route", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
"RouteKey": "sendmessage", | ||
"AuthorizationType": "NONE", | ||
"Target": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"integrations/", | ||
{ | ||
"Ref": "mywsapisendmessageRouteSendMessageIntegrationD29E12F9" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
}, | ||
"mystage114C35EC": { | ||
"Type": "AWS::ApiGatewayV2::Stage", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
"StageName": "dev", | ||
"AutoDeploy": true | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ApiEndpoint": { | ||
"Value": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"wss://", | ||
{ | ||
"Ref": "mywsapi32E6CE11" | ||
}, | ||
".execute-api.", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
".", | ||
{ | ||
"Ref": "AWS::URLSuffix" | ||
}, | ||
"/dev" | ||
] | ||
] | ||
} | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/@aws-cdk/aws-apigatewayv2-integrations/test/websocket/integ.mock.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,24 @@ | ||
import { WebSocketApi, WebSocketStage } from '@aws-cdk/aws-apigatewayv2'; | ||
import { App, CfnOutput, Stack } from '@aws-cdk/core'; | ||
import { WebSocketMockIntegration } from '../../lib'; | ||
|
||
/* | ||
* Stack verification steps: | ||
* 1. Verify manually that the integration has type "MOCK" | ||
*/ | ||
|
||
const app = new App(); | ||
const stack = new Stack(app, 'integ-mock-websocket-integration'); | ||
|
||
const webSocketApi = new WebSocketApi(stack, 'mywsapi', { | ||
defaultRouteOptions: { integration: new WebSocketMockIntegration('DefaultIntegration') }, | ||
}); | ||
const stage = new WebSocketStage(stack, 'mystage', { | ||
webSocketApi, | ||
stageName: 'dev', | ||
autoDeploy: true, | ||
}); | ||
|
||
webSocketApi.addRoute('sendmessage', { integration: new WebSocketMockIntegration('SendMessageIntegration') }); | ||
|
||
new CfnOutput(stack, 'ApiEndpoint', { value: stage.url }); |
23 changes: 23 additions & 0 deletions
23
packages/@aws-cdk/aws-apigatewayv2-integrations/test/websocket/mock.test.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,23 @@ | ||
import { Template } from '@aws-cdk/assertions'; | ||
import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2'; | ||
import { Stack } from '@aws-cdk/core'; | ||
import { WebSocketMockIntegration } from '../../lib'; | ||
|
||
|
||
describe('MockWebSocketIntegration', () => { | ||
test('default', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
new WebSocketApi(stack, 'Api', { | ||
defaultRouteOptions: { integration: new WebSocketMockIntegration('DefaultIntegration') }, | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::ApiGatewayV2::Integration', { | ||
IntegrationType: 'MOCK', | ||
IntegrationUri: '', | ||
}); | ||
}); | ||
}); |
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