-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add end-to-end test for ApiGatewayV2 #644
Open
SankyRed
wants to merge
4
commits into
main
Choose a base branch
from
SankyRed/apigatewayv2-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Amazon.CDK; | ||
using Amazon.CDK.AWS.ApiGatewayV2; | ||
using Constructs; | ||
using System.Collections.Generic; | ||
|
||
namespace ApiGatewayV2Stack | ||
{ | ||
public class ApiGatewayV2StackProps : StackProps | ||
{ | ||
} | ||
|
||
public class ApiGatewayV2Stack : Stack | ||
{ | ||
/// <summary> | ||
/// Endpoint for the HTTP API | ||
/// </summary> | ||
public object ApiEndpoint { get; } | ||
|
||
public ApiGatewayV2Stack(Construct scope, string id, ApiGatewayV2StackProps props = null) : base(scope, id, props) | ||
{ | ||
|
||
// Resources | ||
var myApi = new CfnApi(this, "MyApi", new CfnApiProps | ||
{ | ||
Name = "MyHttpApi", | ||
ProtocolType = "HTTP", | ||
Description = "My HTTP API", | ||
}); | ||
var defaultStage = new CfnStage(this, "DefaultStage", new CfnStageProps | ||
{ | ||
ApiId = myApi.Ref, | ||
StageName = "default", | ||
AutoDeploy = true, | ||
}); | ||
var helloWorldIntegration = new CfnIntegration(this, "HelloWorldIntegration", new CfnIntegrationProps | ||
{ | ||
ApiId = myApi.Ref, | ||
IntegrationType = "HTTP_PROXY", | ||
IntegrationUri = "https://jsonplaceholder.typicode.com/posts/1", | ||
IntegrationMethod = "GET", | ||
PayloadFormatVersion = "1.0", | ||
}); | ||
var helloWorldRoute = new CfnRoute(this, "HelloWorldRoute", new CfnRouteProps | ||
{ | ||
ApiId = myApi.Ref, | ||
RouteKey = "GET /hello", | ||
Target = string.Join("/", new [] | ||
{ | ||
"integrations", | ||
helloWorldIntegration.Ref, | ||
}), | ||
}); | ||
|
||
// Outputs | ||
ApiEndpoint = $"https://{myApi.Ref}.execute-api.{Region}.amazonaws.com/default"; | ||
} | ||
} | ||
} |
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,79 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
cdk "github.com/aws/aws-cdk-go/awscdk/v2" | ||
apigatewayv2 "github.com/aws/aws-cdk-go/awscdk/v2/awsapigatewayv2" | ||
"github.com/aws/constructs-go/constructs/v10" | ||
"github.com/aws/jsii-runtime-go" | ||
) | ||
|
||
type ApiGatewayV2StackProps struct { | ||
cdk.StackProps | ||
} | ||
|
||
type ApiGatewayV2Stack struct { | ||
cdk.Stack | ||
/// Endpoint for the HTTP API | ||
ApiEndpoint interface{} // TODO: fix to appropriate type | ||
} | ||
|
||
func NewApiGatewayV2Stack(scope constructs.Construct, id string, props *ApiGatewayV2StackProps) *ApiGatewayV2Stack { | ||
var sprops cdk.StackProps | ||
if props != nil { | ||
sprops = props.StackProps | ||
} | ||
stack := cdk.NewStack(scope, &id, &sprops) | ||
|
||
myApi := api_gateway_v2.NewCfnApi( | ||
stack, | ||
jsii.String("MyApi"), | ||
&api_gateway_v2.CfnApiProps{ | ||
Name: jsii.String("MyHttpApi"), | ||
ProtocolType: jsii.String("HTTP"), | ||
Description: jsii.String("My HTTP API"), | ||
}, | ||
) | ||
|
||
api_gateway_v2.NewCfnStage( | ||
stack, | ||
jsii.String("DefaultStage"), | ||
&api_gateway_v2.CfnStageProps{ | ||
ApiId: myApi.Ref(), | ||
StageName: jsii.String("default"), | ||
AutoDeploy: jsii.Bool(true), | ||
}, | ||
) | ||
|
||
helloWorldIntegration := api_gateway_v2.NewCfnIntegration( | ||
stack, | ||
jsii.String("HelloWorldIntegration"), | ||
&api_gateway_v2.CfnIntegrationProps{ | ||
ApiId: myApi.Ref(), | ||
IntegrationType: jsii.String("HTTP_PROXY"), | ||
IntegrationUri: jsii.String("https://jsonplaceholder.typicode.com/posts/1"), | ||
IntegrationMethod: jsii.String("GET"), | ||
PayloadFormatVersion: jsii.String("1.0"), | ||
}, | ||
) | ||
|
||
api_gateway_v2.NewCfnRoute( | ||
stack, | ||
jsii.String("HelloWorldRoute"), | ||
&api_gateway_v2.CfnRouteProps{ | ||
ApiId: myApi.Ref(), | ||
RouteKey: jsii.String("GET /hello"), | ||
Target: cdk.Fn_Join(jsii.String("/"), &[]*string{ | ||
jsii.String("integrations"), | ||
helloWorldIntegration.Ref(), | ||
}), | ||
}, | ||
) | ||
|
||
return &ApiGatewayV2Stack{ | ||
Stack: stack, | ||
ApiEndpoint: jsii.String(fmt.Sprintf("https://%v.execute-api.%v.amazonaws.com/default", myApi.Ref(), stack.Region())), | ||
} | ||
} | ||
|
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,98 @@ | ||
diff --git a/./tests/end-to-end/apigatewayv2/template.json b/tests/end-to-end/apigatewayv2-java-working-dir/cdk.out/Stack.template.json | ||
index fd7cdf1..442de83 100644 | ||
--- a/./tests/end-to-end/apigatewayv2/template.json | ||
+++ b/tests/end-to-end/apigatewayv2-java-working-dir/cdk.out/Stack.template.json | ||
@@ -1,12 +1,11 @@ | ||
{ | ||
- "AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyApi": { | ||
"Type": "AWS::ApiGatewayV2::Api", | ||
"Properties": { | ||
+ "Description": "My HTTP API", | ||
"Name": "MyHttpApi", | ||
- "ProtocolType": "HTTP", | ||
- "Description": "My HTTP API" | ||
+ "ProtocolType": "HTTP" | ||
} | ||
}, | ||
"DefaultStage": { | ||
@@ -15,8 +14,20 @@ | ||
"ApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
- "StageName": "default", | ||
- "AutoDeploy": true | ||
+ "AutoDeploy": true, | ||
+ "StageName": "default" | ||
+ } | ||
+ }, | ||
+ "HelloWorldIntegration": { | ||
+ "Type": "AWS::ApiGatewayV2::Integration", | ||
+ "Properties": { | ||
+ "ApiId": { | ||
+ "Ref": "MyApi" | ||
+ }, | ||
+ "IntegrationMethod": "GET", | ||
+ "IntegrationType": "HTTP_PROXY", | ||
+ "IntegrationUri": "https://jsonplaceholder.typicode.com/posts/1", | ||
+ "PayloadFormatVersion": "1.0" | ||
} | ||
}, | ||
"HelloWorldRoute": { | ||
@@ -28,9 +39,9 @@ | ||
"RouteKey": "GET /hello", | ||
"Target": { | ||
"Fn::Join": [ | ||
- "/", | ||
+ "", | ||
[ | ||
- "integrations", | ||
+ "integrations/", | ||
{ | ||
"Ref": "HelloWorldIntegration" | ||
} | ||
@@ -38,27 +49,27 @@ | ||
] | ||
} | ||
} | ||
- }, | ||
- "HelloWorldIntegration": { | ||
- "Type": "AWS::ApiGatewayV2::Integration", | ||
- "Properties": { | ||
- "ApiId": { | ||
- "Ref": "MyApi" | ||
- }, | ||
- "IntegrationType": "HTTP_PROXY", | ||
- "IntegrationUri": "https://jsonplaceholder.typicode.com/posts/1", | ||
- "IntegrationMethod": "GET", | ||
- "PayloadFormatVersion": "1.0" | ||
- } | ||
} | ||
}, | ||
"Outputs": { | ||
"ApiEndpoint": { | ||
"Description": "Endpoint for the HTTP API", | ||
"Value": { | ||
- "Fn::Sub": "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/default" | ||
+ "Fn::Join": [ | ||
+ "", | ||
+ [ | ||
+ "https://", | ||
+ { | ||
+ "Ref": "MyApi" | ||
+ }, | ||
+ ".execute-api.", | ||
+ { | ||
+ "Ref": "AWS::Region" | ||
+ }, | ||
+ ".amazonaws.com/default" | ||
+ ] | ||
+ ] | ||
} | ||
} | ||
} | ||
} | ||
\ No newline at end of file | ||
- | ||
\ No newline at end of file |
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,75 @@ | ||
{ | ||
"Resources": { | ||
"MyApi": { | ||
"Type": "AWS::ApiGatewayV2::Api", | ||
"Properties": { | ||
"Description": "My HTTP API", | ||
"Name": "MyHttpApi", | ||
"ProtocolType": "HTTP" | ||
} | ||
}, | ||
"DefaultStage": { | ||
"Type": "AWS::ApiGatewayV2::Stage", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"AutoDeploy": true, | ||
"StageName": "default" | ||
} | ||
}, | ||
"HelloWorldIntegration": { | ||
"Type": "AWS::ApiGatewayV2::Integration", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"IntegrationMethod": "GET", | ||
"IntegrationType": "HTTP_PROXY", | ||
"IntegrationUri": "https://jsonplaceholder.typicode.com/posts/1", | ||
"PayloadFormatVersion": "1.0" | ||
} | ||
}, | ||
"HelloWorldRoute": { | ||
"Type": "AWS::ApiGatewayV2::Route", | ||
"Properties": { | ||
"ApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"RouteKey": "GET /hello", | ||
"Target": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"integrations/", | ||
{ | ||
"Ref": "HelloWorldIntegration" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ApiEndpoint": { | ||
"Description": "Endpoint for the HTTP API", | ||
"Value": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"https://", | ||
{ | ||
"Ref": "MyApi" | ||
}, | ||
".execute-api.", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
".amazonaws.com/default" | ||
] | ||
] | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/end-to-end/apigatewayv2/java/src/main/java/com/myorg/MyApp.java
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,19 @@ | ||
//auto-generated | ||
package com.myorg; | ||
import software.amazon.awscdk.App; | ||
import software.amazon.awscdk.AppProps; | ||
import software.amazon.awscdk.DefaultStackSynthesizer; | ||
import software.amazon.awscdk.StackProps; | ||
public class MyApp { | ||
public static void main(final String[] args) { | ||
App app = new App(AppProps.builder() | ||
.defaultStackSynthesizer(DefaultStackSynthesizer.Builder.create() | ||
.generateBootstrapVersionRule(false) | ||
.build()) | ||
.build()); | ||
new ApiGatewayV2Stack(app, "Stack", StackProps.builder() | ||
.build()); | ||
app.synth(); | ||
|
||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about not synthesizing python and csharp. If these aren't working you may have uncovered a bug. Could you remove these and we can debug the failing tests?