Skip to content

Commit

Permalink
First set of PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gcbeattyAWS committed Dec 18, 2024
1 parent 8cfbc0a commit b4cd801
Show file tree
Hide file tree
Showing 17 changed files with 866 additions and 707 deletions.
12 changes: 12 additions & 0 deletions Tools/LambdaTestTool-v2/Amazon.Lambda.TestTool.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.TestTool", "src\Amazon.Lambda.TestTool\Amazon.Lambda.TestTool.csproj", "{97EE2E8A-D1F4-CB11-B664-B99B036E9F7B}"
Expand All @@ -8,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.TestTool.UnitTests", "tests\Amazon.Lambda.TestTool.UnitTests\Amazon.Lambda.TestTool.UnitTests.csproj", "{80A4F809-28B7-61EC-6539-DF3C7A0733FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.TestTool.IntegrationTests", "tests\Amazon.Lambda.TestTool.IntegrationTests\Amazon.Lambda.TestTool.IntegrationTests.csproj", "{5C1B3E1C-DFEA-425B-8ED2-BB43BAECC3CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,6 +27,13 @@ Global
{80A4F809-28B7-61EC-6539-DF3C7A0733FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80A4F809-28B7-61EC-6539-DF3C7A0733FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80A4F809-28B7-61EC-6539-DF3C7A0733FD}.Release|Any CPU.Build.0 = Release|Any CPU
{5C1B3E1C-DFEA-425B-8ED2-BB43BAECC3CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C1B3E1C-DFEA-425B-8ED2-BB43BAECC3CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C1B3E1C-DFEA-425B-8ED2-BB43BAECC3CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C1B3E1C-DFEA-425B-8ED2-BB43BAECC3CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{97EE2E8A-D1F4-CB11-B664-B99B036E9F7B} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -12,7 +12,8 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
<PackageReference Include="AWSSDK.APIGateway" Version="3.7.401.7" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.401.7" />
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.401.11" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.402" />
<PackageReference Include="AWSSDK.ApiGatewayV2" Version="3.7.400.63" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.408.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
Expand All @@ -27,8 +28,13 @@
<ProjectReference Include="..\..\src\Amazon.Lambda.TestTool\Amazon.Lambda.TestTool.csproj" />
<ProjectReference Include="..\Amazon.Lambda.TestTool.UnitTests\Amazon.Lambda.TestTool.UnitTests.csproj" />
</ItemGroup>

<ItemGroup>

<ItemGroup>
<EmbeddedResource Include="cloudformation-template-apigateway.yaml" />
</ItemGroup>


<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.TestTool.IntegrationTests", "Amazon.Lambda.TestTool.IntegrationTests.csproj", "{94C7903E-A21A-43EC-BB04-C9DA404F1C02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{94C7903E-A21A-43EC-BB04-C9DA404F1C02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94C7903E-A21A-43EC-BB04-C9DA404F1C02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94C7903E-A21A-43EC-BB04-C9DA404F1C02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94C7903E-A21A-43EC-BB04-C9DA404F1C02}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {429CE21F-1692-4C50-A9E6-299AB413D027}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

namespace Amazon.Lambda.TestTool.IntegrationTests
{
[CollectionDefinition("ApiGateway Integration Tests")]
public class ApiGatewayIntegrationTestCollection : ICollectionFixture<ApiGatewayIntegrationTestFixture>
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using Amazon.CloudFormation;
using Amazon.APIGateway;
using Amazon.ApiGatewayV2;
using Amazon.Lambda.TestTool.IntegrationTests.Helpers;
using System.Reflection;

namespace Amazon.Lambda.TestTool.IntegrationTests
{
public class ApiGatewayIntegrationTestFixture : IAsyncLifetime
{
public CloudFormationHelper CloudFormationHelper { get; private set; }
public ApiGatewayHelper ApiGatewayHelper { get; private set; }
public ApiGatewayTestHelper ApiGatewayTestHelper { get; private set; }

public string StackName { get; private set; }
public string RestApiId { get; private set; }
public string HttpApiV1Id { get; private set; }
public string HttpApiV2Id { get; private set; }
public string ReturnRawRequestBodyV2Id { get; private set; }
public string RestApiUrl { get; private set; }
public string HttpApiV1Url { get; private set; }
public string HttpApiV2Url { get; private set; }
public string ReturnRawRequestBodyHttpApiV2Url { get; private set; }

public ApiGatewayIntegrationTestFixture()
{
var regionEndpoint = RegionEndpoint.USWest2;
CloudFormationHelper = new CloudFormationHelper(new AmazonCloudFormationClient(regionEndpoint));
ApiGatewayHelper = new ApiGatewayHelper(
new AmazonAPIGatewayClient(regionEndpoint),
new AmazonApiGatewayV2Client(regionEndpoint)
);
ApiGatewayTestHelper = new ApiGatewayTestHelper();
StackName = string.Empty;
RestApiId = string.Empty;
HttpApiV1Id = string.Empty;
HttpApiV2Id = string.Empty;
ReturnRawRequestBodyV2Id = string.Empty;
RestApiUrl = string.Empty;
HttpApiV1Url = string.Empty;
HttpApiV2Url = string.Empty;
ReturnRawRequestBodyHttpApiV2Url = string.Empty;
}

public async Task InitializeAsync()
{
StackName = $"Test-{Guid.NewGuid().ToString("N").Substring(0, 5)}";

string templateBody = ReadCloudFormationTemplate("cloudformation-template-apigateway.yaml");
await CloudFormationHelper.CreateStackAsync(StackName, templateBody);

await WaitForStackCreationComplete();
await RetrieveStackOutputs();
await WaitForApisAvailability();
}

private string ReadCloudFormationTemplate(string fileName)
{
var assembly = Assembly.GetExecutingAssembly();
var resourceName = $"{assembly.GetName().Name}.{fileName}";
using (var stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
{
throw new FileNotFoundException($"CloudFormation template file '{fileName}' not found in assembly resources.");
}

using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}

private async Task WaitForStackCreationComplete()
{
while (true)
{
var status = await CloudFormationHelper.GetStackStatusAsync(StackName);
if (status == StackStatus.CREATE_COMPLETE)
{
break;
}
if (status.ToString().EndsWith("FAILED") || status == StackStatus.DELETE_COMPLETE)
{
throw new Exception($"Stack creation failed. Status: {status}");
}
await Task.Delay(10000);
}
}

private async Task RetrieveStackOutputs()
{
RestApiId = await CloudFormationHelper.GetOutputValueAsync(StackName, "RestApiId");
RestApiUrl = await CloudFormationHelper.GetOutputValueAsync(StackName, "RestApiUrl");

HttpApiV1Id = await CloudFormationHelper.GetOutputValueAsync(StackName, "HttpApiV1Id");
HttpApiV1Url = await CloudFormationHelper.GetOutputValueAsync(StackName, "HttpApiV1Url");

HttpApiV2Id = await CloudFormationHelper.GetOutputValueAsync(StackName, "HttpApiV2Id");
HttpApiV2Url = await CloudFormationHelper.GetOutputValueAsync(StackName, "HttpApiV2Url");

ReturnRawRequestBodyV2Id = await CloudFormationHelper.GetOutputValueAsync(StackName, "ReturnRawRequestBodyHttpApiId");
ReturnRawRequestBodyHttpApiV2Url = await CloudFormationHelper.GetOutputValueAsync(StackName, "ReturnRawRequestBodyHttpApiUrl");
}

private async Task WaitForApisAvailability()
{
await ApiGatewayHelper.WaitForApiAvailability(RestApiId, RestApiUrl, false);
await ApiGatewayHelper.WaitForApiAvailability(HttpApiV1Id, HttpApiV1Url, true);
await ApiGatewayHelper.WaitForApiAvailability(HttpApiV2Id, HttpApiV2Url, true);
await ApiGatewayHelper.WaitForApiAvailability(ReturnRawRequestBodyV2Id, ReturnRawRequestBodyHttpApiV2Url, true);
}

public async Task DisposeAsync()
{
await CloudFormationHelper.DeleteStackAsync(StackName);
}
}
}

This file was deleted.

Loading

0 comments on commit b4cd801

Please sign in to comment.