Skip to content
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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/end-to-end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test_case!(cloudwatch, "CloudwatchStack", &["golang"]);
test_case!(ecs, "EcsStack", &["java", "golang"]);
test_case!(ec2, "Ec2Stack", &["java", "golang"]);
test_case!(efs, "EfsStack", &["java", "golang"]);
test_case!(apigatewayv2, "ApiGatewayV2Stack", &["csharp", "golang", "python"]);
Copy link
Contributor

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?


// Add new test cases here

Expand Down
58 changes: 58 additions & 0 deletions tests/end-to-end/apigatewayv2/csharp/Stack.cs
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";
}
}
}
79 changes: 79 additions & 0 deletions tests/end-to-end/apigatewayv2/golang/stack.go
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())),
}
}

98 changes: 98 additions & 0 deletions tests/end-to-end/apigatewayv2/java/Stack.diff
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
75 changes: 75 additions & 0 deletions tests/end-to-end/apigatewayv2/java/Stack.template.json
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"
]
]
}
}
}
}
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();

}
}
Loading
Loading