From 33db274f0fb16ee9ae50897481e87b110ecf1114 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 10:51:55 -0400 Subject: [PATCH 1/9] Add snapshots --- ...on.Lambda.TestTool.IntegrationTests.csproj | 6 +- .../ApiGatewayIntegrationTestFixture.cs | 4 +- ...atewayResponseExtensionsAdditionalTests.cs | 65 ++++++--- .../ApiGatewayResponseExtensionsTests.cs | 44 +++--- .../Helpers/ApiGatewayHelper.cs | 4 +- .../Helpers/ApiGatewayTestHelper.cs | 78 +++++++++-- .../snapshot/ApiGatewayTestSnapshot.cs | 70 ++++++++++ .../Helpers/snapshot/SnapshotTestHelper.cs | 45 ++++++ .../HttpContextExtensionsTests.cs | 129 +++++++++++------- ...nvokeResponseExtensionsIntegrationTests.cs | 41 +++--- .../Snapshots/BinaryContentHttpV1.json | 87 ++++++++++++ .../Snapshots/BinaryContentRest.json | 83 +++++++++++ ...odeAsFloat_ReturnsInternalServerError.json | 21 +++ ...ValidResponse_MatchesDirectConversion.json | 21 +++ ...nvalidJson_ReturnsErrorResponseHttpV1.json | 21 +++ ..._InvalidJson_ReturnsErrorResponseRest.json | 27 ++++ ...esponse_MatchesDirectConversionHttpV1.json | 21 +++ ...ConversionInvalid_JSON_Partial_Object.json | 21 +++ ...nse_MatchesDirectConversionJSON_Array.json | 21 +++ ...dResponse_MatchesDirectConversionRest.json | 27 ++++ ...chesDirectConversionValid_JSON_Object.json | 21 +++ ...sponse_MatchesDirectConversionboolean.json | 21 +++ ...e_MatchesDirectConversionempty_string.json | 21 +++ ...e_MatchesDirectConversionjson_special.json | 21 +++ ...esponse_MatchesDirectConversionnumber.json | 21 +++ ...esponse_MatchesDirectConversionstring.json | 21 +++ ..._MatchesDirectConversionstring_spaces.json | 21 +++ ...tchesDirectConversionstring_unescaped.json | 21 +++ ...ponse_HttpV1APIGatewayV1DecodesBase64.json | 21 +++ ...esponse_RestAPIGatewayV1DecodesBase64.json | 27 ++++ .../Snapshots/V1_APIHeadersHttpV1.json | 21 +++ .../Snapshots/V1_APIHeadersRest.json | 27 ++++ ...binesSingleAndMultiValueHeadersHttpV1.json | 33 +++++ ...ombinesSingleAndMultiValueHeadersRest.json | 39 ++++++ ...V1_DefaultsToCorrectContentTYpeHttpV1.json | 21 +++ .../V1_DefaultsToCorrectContentTYpeRest.json | 27 ++++ .../V1_HandlesHeadersCorrectlyHttpV1.json | 31 +++++ .../V1_HandlesHeadersCorrectlyRest.json | 37 +++++ .../V1_HandlesZeroStatusCodeHttpV1.json | 21 +++ .../V1_HandlesZeroStatusCodeRest.json | 27 ++++ .../Snapshots/V1_SetsBodyNonBase64HttpV1.json | 21 +++ .../Snapshots/V1_SetsBodyNonBase64Rest.json | 27 ++++ .../Snapshots/V1_SetsContentLengthHttpV1.json | 21 +++ .../Snapshots/V1_SetsContentLengthRest.json | 27 ++++ .../V1_SetsCorrectStatusCodeHttpV1.json | 21 +++ .../V1_SetsCorrectStatusCodeRest.json | 27 ++++ .../Snapshots/V1_SetsHeadersHttpV1.json | 24 ++++ .../Snapshots/V1_SetsHeadersRest.json | 30 ++++ .../V1_SetsMultiValueHeadersHttpV1.json | 25 ++++ .../V1_SetsMultiValueHeadersRest.json | 31 +++++ .../Snapshots/V1_SimpleGetRequestHttpV1.json | 110 +++++++++++++++ .../Snapshots/V1_SimpleGetRequestRest.json | 106 ++++++++++++++ .../V1_SimpleJsonResponseHttpV1.json | 21 +++ .../Snapshots/V1_SimpleJsonResponseRest.json | 27 ++++ .../V1_SpecialCharactersInPathHttpV1.json | 88 ++++++++++++ .../V1_SpecialCharactersInPathRest.json | 84 ++++++++++++ .../V1_UnicodeCharactersInPathHttpV1.json | 88 ++++++++++++ .../V1_UnicodeCharactersInPathRest.json | 84 ++++++++++++ .../V1_UrlEncodedQueryStringHttpV1.json | 96 +++++++++++++ .../V1_UrlEncodedQueryStringRest.json | 92 +++++++++++++ .../V1_UsesProvidedContentTypeHttpV1.json | 21 +++ .../V1_UsesProvidedContentTypeRest.json | 27 ++++ .../Snapshots/V2_BinaryContent.json | 44 ++++++ .../V2_DefaultsToTextPlainContentType.json | 21 +++ .../V2_DoesNotOverrideExplicitValues.json | 21 +++ .../Snapshots/V2_HandlesHeadersCorrectly.json | 27 ++++ .../Snapshots/V2_HandlesZeroStatusCode.json | 21 +++ .../Snapshots/V2_HttpAPIHeaders.json | 21 +++ .../Snapshots/V2_SetsBodyBase64.json | 21 +++ .../Snapshots/V2_SetsBodyNonBase64.json | 21 +++ .../Snapshots/V2_SetsCorrectStatusCode.json | 21 +++ .../Snapshots/V2_SetsHeaders.json | 24 ++++ .../Snapshots/V2_SimpleGetRequest.json | 53 +++++++ .../Snapshots/V2_SimpleJsonResponse.json | 21 +++ .../Snapshots/V2_SpecialCharactersInPath.json | 45 ++++++ .../Snapshots/V2_UnicodeCharactersInPath.json | 45 ++++++ .../Snapshots/V2_UrlEncodedQueryString.json | 45 ++++++ 77 files changed, 2754 insertions(+), 131 deletions(-) create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj index 8e2088d92..a7753846f 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -44,4 +44,8 @@ + + + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs index 9f83cb6ef..dd50f9796 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs @@ -14,7 +14,7 @@ namespace Amazon.Lambda.TestTool.IntegrationTests public class ApiGatewayIntegrationTestFixture : IAsyncLifetime { private readonly Dictionary _testRoutes; - + public CloudFormationHelper CloudFormationHelper { get; private set; } public ApiGatewayHelper ApiGatewayHelper { get; private set; } public ApiGatewayTestHelper ApiGatewayTestHelper { get; private set; } @@ -137,7 +137,7 @@ public static ApiGatewayEmulatorMode GetEmulatorMode(ApiGatewayType gatewayType) _ => throw new ArgumentException($"Unsupported gateway type: {gatewayType}") }; } - + public async Task InitializeAsync() { diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs index 22d95b857..4f305d7c4 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs @@ -7,6 +7,7 @@ using Amazon.Lambda.TestTool.Extensions; using Amazon.Lambda.TestTool.Models; using System.Text; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; using Xunit; namespace Amazon.Lambda.TestTool.IntegrationTests @@ -16,11 +17,19 @@ public class ApiGatewayResponseExtensionsAdditionalTests { private readonly ApiGatewayIntegrationTestFixture _fixture; private readonly HttpClient _httpClient; + private readonly SnapshotTestHelper _snapshots; + public ApiGatewayResponseExtensionsAdditionalTests(ApiGatewayIntegrationTestFixture fixture) { _fixture = fixture; _httpClient = new HttpClient(); + _snapshots = new SnapshotTestHelper(new JsonSerializerOptions + { + WriteIndented = true, + Converters = { new HttpResponseMessageConverter() } + } + ); } [Fact] @@ -36,14 +45,27 @@ public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() var httpContext = new DefaultHttpContext(); httpContext.Response.Body = new MemoryStream(); await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.Rest); - - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.RestWithBinarySupport); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.DecodeParseBinary); - var actualResponse = await _httpClient.PostAsync(url, new StringContent(JsonSerializer.Serialize(testResponse)), new CancellationTokenSource(5000).Token); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response); - Assert.Equal(200, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal("test", content); + + if (_snapshots.IsUpdatingSnapshots) + { + var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.RestWithBinarySupport); + var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.DecodeParseBinary); + var actualResponse = await _httpClient.PostAsync( + url, + new StringContent(JsonSerializer.Serialize(testResponse)), + new CancellationTokenSource(5000).Token); + + await _snapshots.SaveSnapshot(actualResponse, nameof(ToHttpResponse_RestAPIGatewayV1DecodesBase64)); + } + else + { + var snapshot = await _snapshots.LoadSnapshot( + nameof(ToHttpResponse_RestAPIGatewayV1DecodesBase64)); + + Assert.Equal(200, (int)snapshot.StatusCode); + var content = await snapshot.Content.ReadAsStringAsync(); + Assert.Equal("test", content); + } } [Fact] @@ -56,18 +78,27 @@ public async Task ToHttpResponse_HttpV1APIGatewayV1DecodesBase64() IsBase64Encoded = true }; - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.HttpV1); - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV1); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var actualResponse = await _httpClient.PostAsync(url, new StringContent(JsonSerializer.Serialize(testResponse)), new CancellationTokenSource(5000).Token); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response); - Assert.Equal(200, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal("test", content); + if (_snapshots.IsUpdatingSnapshots) + { + var actualResponse = await _httpClient.PostAsync( + url, + new StringContent(JsonSerializer.Serialize(testResponse)), + new CancellationTokenSource(5000).Token); + + await _snapshots.SaveSnapshot(actualResponse, nameof(ToHttpResponse_HttpV1APIGatewayV1DecodesBase64)); + } + else + { + var snapshot = await _snapshots.LoadSnapshot( + nameof(ToHttpResponse_HttpV1APIGatewayV1DecodesBase64)); + + Assert.Equal(200, (int)snapshot.StatusCode); + var content = await snapshot.Content.ReadAsStringAsync(); + Assert.Equal("test", content); + } } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs index e3752faab..e33b50269 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 using Amazon.Lambda.APIGatewayEvents; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; using Amazon.Lambda.TestTool.Tests.Common; using Xunit; @@ -25,13 +24,9 @@ public ApiGatewayResponseExtensionsTests(ApiGatewayIntegrationTestFixture fixtur [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public async Task IntegrationTest_APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) { - await RetryHelper.RetryOperation(async () => - { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.Rest); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - await RunV1Test(testCase, url, ApiGatewayEmulatorMode.Rest); - return true; - }); + var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.Rest); + var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); + await RunV1Test(testCase, url, ApiGatewayEmulatorMode.Rest, testName); } [Theory] @@ -39,13 +34,9 @@ await RetryHelper.RetryOperation(async () => [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public async Task IntegrationTest_APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) { - await RetryHelper.RetryOperation(async () => - { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV1); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - await RunV1Test(testCase, url, ApiGatewayEmulatorMode.HttpV1); - return true; - }); + var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV1); + var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); + await RunV1Test(testCase, url, ApiGatewayEmulatorMode.HttpV1, testName); } [Theory] @@ -53,24 +44,21 @@ await RetryHelper.RetryOperation(async () => [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) { - await RetryHelper.RetryOperation(async () => - { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; - Assert.NotNull(testResponse); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, url); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); - await testCase.IntegrationAssertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); - return true; - }); + var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); + var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); + var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; + Assert.NotNull(testResponse); + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, url, testName); + await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + await testCase.IntegrationAssertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); } - private async Task RunV1Test(ApiGatewayResponseTestCase testCase, string apiUrl, ApiGatewayEmulatorMode emulatorMode) + private async Task RunV1Test(ApiGatewayResponseTestCase testCase, string apiUrl, ApiGatewayEmulatorMode emulatorMode, string testName) { var testResponse = testCase.Response as APIGatewayProxyResponse; Assert.NotNull(testResponse); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, apiUrl, emulatorMode); + var testCaseName = testName + emulatorMode; + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, apiUrl, emulatorMode, testCaseName); await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); await testCase.IntegrationAssertions(actualResponse, emulatorMode); } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs index 5818bf3e0..f0bdb3c72 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs @@ -6,8 +6,6 @@ using Amazon.APIGateway.Model; using Amazon.ApiGatewayV2.Model; using System.Net; -using Amazon.Runtime.Internal.Endpoints.StandardLibrary; -using ConflictException = Amazon.ApiGatewayV2.Model.ConflictException; namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers { @@ -202,7 +200,7 @@ await _apiGatewayV2Client.CreateRouteAsync(new CreateRouteRequest }); // Create stage if it doesn't exist - try + try { await _apiGatewayV2Client.CreateStageAsync(new Amazon.ApiGatewayV2.Model.CreateStageRequest { diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs index b4584e198..aa26f335d 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs @@ -1,9 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +using System.Runtime.CompilerServices; using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; using Amazon.Lambda.TestTool.Models; using Microsoft.AspNetCore.Http; using Xunit; @@ -12,29 +14,81 @@ namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers { public class ApiGatewayTestHelper { - private readonly HttpClient _httpClient; + private readonly SnapshotTestHelper _snapshots; public ApiGatewayTestHelper() { - _httpClient = new HttpClient(); + _snapshots = new SnapshotTestHelper(new JsonSerializerOptions + { + WriteIndented = true, + Converters = { new HttpResponseMessageConverter() } + } + ); } - public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest(APIGatewayProxyResponse testResponse, string apiUrl, ApiGatewayEmulatorMode emulatorMode) + + public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( + APIGatewayProxyResponse testResponse, + string apiUrl, + ApiGatewayEmulatorMode emulatorMode, + string testName) { - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(httpContext, emulatorMode); - var serialized = JsonSerializer.Serialize(testResponse); - var actualResponse = await _httpClient.PostAsync(apiUrl, new StringContent(serialized), new CancellationTokenSource(5000).Token); - return (actualResponse, httpContext.Response); + // Generate the expected response using ToHttpResponseAsync + var testResponseHttpContext = new DefaultHttpContext(); + testResponseHttpContext.Response.Body = new MemoryStream(); + await testResponse.ToHttpResponseAsync(testResponseHttpContext, emulatorMode); + + HttpResponseMessage actualResponse; + if (_snapshots.IsUpdatingSnapshots) + { + // When updating snapshots, we need to make the real API call + using var httpClient = new HttpClient(); + var serialized = JsonSerializer.Serialize(testResponse); + actualResponse = await httpClient.PostAsync( + apiUrl, + new StringContent(serialized), + new CancellationTokenSource(5000).Token); + + await _snapshots.SaveSnapshot(actualResponse, testName); + } + else + { + // Load existing snapshot and verify + actualResponse = await _snapshots.LoadSnapshot(testName); + } + + return (actualResponse, testResponseHttpContext.Response); + } - public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest(APIGatewayHttpApiV2ProxyResponse testResponse, string apiUrl) + public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( + APIGatewayHttpApiV2ProxyResponse testResponse, + string apiUrl, + string testName) { + // Generate the expected response using ToHttpResponseAsync var testResponseHttpContext = new DefaultHttpContext(); testResponseHttpContext.Response.Body = new MemoryStream(); await testResponse.ToHttpResponseAsync(testResponseHttpContext); - var serialized = JsonSerializer.Serialize(testResponse); - var actualResponse = await _httpClient.PostAsync(apiUrl, new StringContent(serialized), new CancellationTokenSource(5000).Token); + + HttpResponseMessage actualResponse; + if (_snapshots.IsUpdatingSnapshots) + { + // When updating snapshots, make the real API call + using var httpClient = new HttpClient(); + var serialized = JsonSerializer.Serialize(testResponse); + actualResponse = await httpClient.PostAsync( + apiUrl, + new StringContent(serialized), + new CancellationTokenSource(5000).Token); + + await _snapshots.SaveSnapshot(actualResponse, testName); + } + else + { + // Load existing snapshot + actualResponse = await _snapshots.LoadSnapshot(testName); + } + return (actualResponse, testResponseHttpContext.Response); } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs new file mode 100644 index 000000000..695fa920a --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs @@ -0,0 +1,70 @@ +using System.Net; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; + +public class HttpResponseMessageConverter : JsonConverter +{ + public override HttpResponseMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + using var document = JsonDocument.ParseValue(ref reader); + var element = document.RootElement; + + var response = new HttpResponseMessage((HttpStatusCode)element.GetProperty("StatusCode").GetInt32()); + + // Set content + var content = element.GetProperty("Content").GetString(); + response.Content = new StringContent(content ?? ""); + + // Clear default headers that StringContent adds + response.Headers.Clear(); + response.Content.Headers.Clear(); + + // Set headers + if (element.TryGetProperty("Headers", out var headersElement)) + { + foreach (var header in headersElement.EnumerateObject()) + { + var values = header.Value.EnumerateArray() + .Select(v => v.GetString()) + .Where(v => v != null) + .ToList(); + + // Try to add to either Headers or Content.Headers + if (!response.Headers.TryAddWithoutValidation(header.Name, values)) + { + response.Content.Headers.TryAddWithoutValidation(header.Name, values); + } + } + } + + return response; + } + + public override void Write(Utf8JsonWriter writer, HttpResponseMessage value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + + // Write status code + writer.WriteNumber("StatusCode", (int)value.StatusCode); + + // Write content + writer.WriteString("Content", value.Content.ReadAsStringAsync().Result); + + // Write headers + writer.WriteStartObject("Headers"); + foreach (var header in value.Headers.Concat(value.Content.Headers)) + { + writer.WriteStartArray(header.Key); + foreach (var headerValue in header.Value) + { + writer.WriteStringValue(headerValue); + } + writer.WriteEndArray(); + } + writer.WriteEndObject(); + + writer.WriteEndObject(); + } +} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs new file mode 100644 index 000000000..e275c0e0e --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs @@ -0,0 +1,45 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text.Json; + +namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; +public class SnapshotTestHelper +{ + private readonly string _snapshotDirectory; + private readonly JsonSerializerOptions _serializerOptions; + public bool IsUpdatingSnapshots => true; + + public SnapshotTestHelper(JsonSerializerOptions? serializerOptions = null, string snapshotDirectory = "Snapshots") + { + var projectDir = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../")); + _snapshotDirectory = Path.Combine(projectDir, snapshotDirectory); + _serializerOptions = serializerOptions ?? new JsonSerializerOptions + { + WriteIndented = true + }; + } + + public async Task SaveSnapshot(T value, string snapshotName) + { + Directory.CreateDirectory(_snapshotDirectory); + var filePath = GetSnapshotPath(snapshotName); + var serialized = JsonSerializer.Serialize(value, _serializerOptions); + await File.WriteAllTextAsync(filePath, serialized); + } + + public async Task LoadSnapshot(string snapshotName) + { + var filePath = GetSnapshotPath(snapshotName); + if (!File.Exists(filePath)) + { + throw new FileNotFoundException($"Snapshot file not found: {filePath}"); + } + + var content = await File.ReadAllTextAsync(filePath); + return JsonSerializer.Deserialize(content, _serializerOptions); + } + + private string GetSnapshotPath(string snapshotName) => + Path.Combine(_snapshotDirectory, $"{snapshotName}.json"); +} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs index de7a510d1..c545ac677 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs @@ -11,7 +11,8 @@ using Microsoft.Extensions.Primitives; using Xunit; using static Amazon.Lambda.TestTool.Tests.Common.HttpContextTestCases; -using System.Net.Http.Headers; +using System.Runtime.CompilerServices; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; namespace Amazon.Lambda.TestTool.IntegrationTests { @@ -19,10 +20,12 @@ namespace Amazon.Lambda.TestTool.IntegrationTests public class HttpContextExtensionsTests { private readonly ApiGatewayIntegrationTestFixture _fixture; + private readonly SnapshotTestHelper _snapshots; public HttpContextExtensionsTests(ApiGatewayIntegrationTestFixture fixture) { _fixture = fixture; + _snapshots = new SnapshotTestHelper(); } [Theory] @@ -30,11 +33,13 @@ public HttpContextExtensionsTests(ApiGatewayIntegrationTestFixture fixture) [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCase testCase) { + var testCaseName = testName + ApiGatewayEmulatorMode.Rest; return RunApiGatewayTest(testCase, new ApiGatewayTestConfig { RouteId = TestRoutes.Ids.ReturnFullEvent, GatewayType = ApiGatewayType.Rest - }); + }, + testCaseName); } [Theory] @@ -42,11 +47,14 @@ public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCa [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) { + var testCaseName = testName + ApiGatewayEmulatorMode.HttpV1; + return RunApiGatewayTest(testCase, new ApiGatewayTestConfig { RouteId = TestRoutes.Ids.ReturnFullEvent, GatewayType = ApiGatewayType.HttpV1 - }); + }, + testCaseName); } [Theory] @@ -58,7 +66,8 @@ public Task IntegrationTest_APIGatewayV2(string testName, HttpContextTestCase te { RouteId = TestRoutes.Ids.ReturnFullEvent, GatewayType = ApiGatewayType.HttpV2 - }); + }, + testName); } [Fact] @@ -97,7 +106,8 @@ public Task BinaryContentHttpV1() { RouteId = TestRoutes.Ids.ReturnFullEvent, GatewayType = ApiGatewayType.HttpV1 - }); + }, + nameof(BinaryContentHttpV1)); } [Fact] @@ -134,10 +144,11 @@ public Task BinaryContentRest() { RouteId = TestRoutes.Ids.ReturnFullEvent, GatewayType = ApiGatewayType.RestWithBinarySupport - }); + }, + nameof(BinaryContentRest)); } - private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayTestConfig config) where T : class + private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayTestConfig config, string testName) where T : class { var baseUrl = _fixture.GetAppropriateBaseUrl(config.GatewayType); @@ -147,11 +158,11 @@ private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGateway Func> converter = config.GatewayType switch { - ApiGatewayType.Rest or ApiGatewayType.RestWithBinarySupport => + ApiGatewayType.Rest or ApiGatewayType.RestWithBinarySupport => async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.Rest), - ApiGatewayType.HttpV1 => + ApiGatewayType.HttpV1 => async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.HttpV1), - ApiGatewayType.HttpV2 => + ApiGatewayType.HttpV2 => async (context, cfg) => (T)(object)await context.ToApiGatewayHttpV2Request(cfg), _ => throw new ArgumentException($"Unsupported gateway type: {config.GatewayType}") }; @@ -162,63 +173,77 @@ await RunApiGatewayTestInternal( apiId, config.RouteId, converter, - emulatorMode); + emulatorMode, + testName); } private async Task RunApiGatewayTestInternal( - HttpContextTestCase testCase, - string baseUrl, + HttpContextTestCase testCase, + string baseUrl, string apiId, string routeId, - Func> toApiGatewayRequest, - ApiGatewayEmulatorMode emulatorMode) + Func> toApiGatewayRequest, + ApiGatewayEmulatorMode emulatorMode, + string testName) where T : class { // Get the route config which has the path prefix var routeConfig = TestRoutes.GetDefaultRoutes(_fixture)[routeId]; - - // Create the route for this specific test - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - await _fixture.ApiGatewayHelper.AddRouteToRestApi( - apiId, - routeConfig.LambdaFunctionArn, - testCase.ApiGatewayRouteConfig.Path, - testCase.ApiGatewayRouteConfig.HttpMethod - ); - } - else // HTTP API v1 or v2 + + T actualApiGatewayRequest; + + if (_snapshots.IsUpdatingSnapshots) { - await _fixture.ApiGatewayHelper.AddRouteToHttpApi( - apiId, - routeConfig.LambdaFunctionArn, - emulatorMode == ApiGatewayEmulatorMode.HttpV2 ? "2.0" : "1.0", - testCase.ApiGatewayRouteConfig.Path, - testCase.ApiGatewayRouteConfig.HttpMethod - ); - } + // Create the route for this specific test + if (emulatorMode == ApiGatewayEmulatorMode.Rest) + { + await _fixture.ApiGatewayHelper.AddRouteToRestApi( + apiId, + routeConfig.LambdaFunctionArn, + testCase.ApiGatewayRouteConfig.Path, + testCase.ApiGatewayRouteConfig.HttpMethod + ); + } + else // HTTP API v1 or v2 + { + await _fixture.ApiGatewayHelper.AddRouteToHttpApi( + apiId, + routeConfig.LambdaFunctionArn, + emulatorMode == ApiGatewayEmulatorMode.HttpV2 ? "2.0" : "1.0", + testCase.ApiGatewayRouteConfig.Path, + testCase.ApiGatewayRouteConfig.HttpMethod + ); + } + + var httpClient = new HttpClient(); + var actualPath = ResolveActualPath(testCase.ApiGatewayRouteConfig.Path, testCase.HttpContext.Request.Path.Value ?? ""); + + var fullUrl = baseUrl.TrimEnd('/') + actualPath + testCase.HttpContext.Request.QueryString.Value; + + // Wait for the API to be available + await _fixture.ApiGatewayHelper.WaitForApiAvailability(apiId, fullUrl, emulatorMode != ApiGatewayEmulatorMode.Rest); + + // Create and send the HTTP request + var httpRequest = CreateHttpRequestMessage(testCase.HttpContext, fullUrl); - var httpClient = new HttpClient(); - var actualPath = ResolveActualPath(testCase.ApiGatewayRouteConfig.Path, testCase.HttpContext.Request.Path.Value ?? ""); - - var stageName = emulatorMode == ApiGatewayEmulatorMode.Rest ? "/test" : ""; - var fullUrl = baseUrl.TrimEnd('/') + actualPath + testCase.HttpContext.Request.QueryString.Value; - - // Wait for the API to be available - await _fixture.ApiGatewayHelper.WaitForApiAvailability(apiId, fullUrl, emulatorMode != ApiGatewayEmulatorMode.Rest); + // Send request and get response + var response = await httpClient.SendAsync(httpRequest); + var responseContent = await response.Content.ReadAsStringAsync(); - // Create and send the HTTP request - var httpRequest = CreateHttpRequestMessage(testCase.HttpContext, fullUrl); + // Verify response + Assert.Equal(200, (int)response.StatusCode); + Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - // Send request and get response - var response = await httpClient.SendAsync(httpRequest); - var responseContent = await response.Content.ReadAsStringAsync(); + actualApiGatewayRequest = JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - // Verify response - Assert.Equal(200, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); + await _snapshots.SaveSnapshot(actualApiGatewayRequest, testName); - var actualApiGatewayRequest = JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + } + else + { + actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); + + } var expectedApiGatewayRequest = await toApiGatewayRequest(testCase.HttpContext, testCase.ApiGatewayRouteConfig); diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs index e49cf6141..09ded4c46 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs @@ -62,10 +62,12 @@ public async Task ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversio // Act var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + var testName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + emulatorMode; + // Assert var baseUrl = _fixture.GetAppropriateBaseUrl(GetGatewayType(emulatorMode)); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode); + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode, testName); await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); } @@ -90,7 +92,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirect // Assert var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url); + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); } @@ -108,13 +110,15 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api // Act var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + var testName = nameof(ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse) + emulatorMode; + // Assert Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); Assert.Contains(expectedErrorMessage, convertedResponse.Body); var baseUrl = _fixture.GetAppropriateBaseUrl(GetGatewayType(emulatorMode)); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, _) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode); + var (actualResponse, _) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode, testName); Assert.Equal(expectedStatusCode, (int)actualResponse.StatusCode); var content = await actualResponse.Content.ReadAsStringAsync(); Assert.Contains(expectedErrorMessage, content); @@ -145,17 +149,20 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api /// correctly replicates this observed behavior, rather than the documented behavior. /// [Theory] - [InlineData("{\"name\": \"John Doe\", \"age\":", "{\"name\": \"John Doe\", \"age\":")] // Invalid JSON (partial object) - [InlineData("{\"name\": \"John Doe\", \"age\": 30}", "{\"name\": \"John Doe\", \"age\": 30}")] // Valid JSON object without statusCode - [InlineData("[1, 2, 3, 4, 5]", "[1, 2, 3, 4, 5]")] // JSON array - [InlineData("Hello, World!", "Hello, World!")] // String primitive - [InlineData("42", "42")] // Number primitive - [InlineData("true", "true")] // Boolean primitive - [InlineData("\"test\"", "test")] // JSON string that should be unescaped - [InlineData("\"Hello, World!\"", "Hello, World!")] // JSON string with spaces - [InlineData("\"\"", "")] // Empty JSON string - [InlineData("\"Special \\\"quoted\\\" text\"", "Special \"quoted\" text")] // JSON string with escaped quotes - public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRawBody(string inputPayload, string expectedResponsePayload) + [InlineData("Invalid_JSON_Partial_Object", "{\"name\": \"John Doe\", \"age\":", "{\"name\": \"John Doe\", \"age\":")] // Invalid JSON (partial object) + [InlineData("Valid_JSON_Object", "{\"name\": \"John Doe\", \"age\": 30}", "{\"name\": \"John Doe\", \"age\": 30}")] // Valid JSON object without statusCode + [InlineData("JSON_Array", "[1, 2, 3, 4, 5]", "[1, 2, 3, 4, 5]")] // JSON array + [InlineData("string", "Hello, World!", "Hello, World!")] // String primitive + [InlineData("number", "42", "42")] // Number primitive + [InlineData("boolean", "true", "true")] // Boolean primitive + [InlineData("string_unescaped", "\"test\"", "test")] // JSON string that should be unescaped + [InlineData("string_spaces", "\"Hello, World!\"", "Hello, World!")] // JSON string with spaces + [InlineData("empty_string", "\"\"", "")] // Empty JSON string + [InlineData("json_special", "\"Special \\\"quoted\\\" text\"", "Special \"quoted\" text")] // JSON string with escaped quotes + public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRawBody( + string testName, + string inputPayload, + string expectedResponsePayload) { // Arrange var invokeResponse = new InvokeResponse @@ -166,6 +173,8 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa // Act var actualConvertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + var testCaseName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + testName; + // Assert Assert.Equal(200, actualConvertedResponse.StatusCode); Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); @@ -174,7 +183,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa // Verify against actual API Gateway behavior var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(actualConvertedResponse, url); + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(actualConvertedResponse, url, testCaseName); await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); // Additional checks for API Gateway specific behavior @@ -205,7 +214,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsIn // Verify against actual API Gateway behavior var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url); + var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); // Additional checks for API Gateway specific behavior diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json new file mode 100644 index 000000000..d0fcc8837 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json @@ -0,0 +1,87 @@ +{ + "Resource": "/test3/api/users/{userId}/avatar", + "Path": "/test3/api/users/123/avatar", + "HttpMethod": "POST", + "Headers": { + "Content-Length": "5", + "Content-Type": "application/octet-stream", + "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd88fd-72d8964e1fed2bce3edd5aac", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Length": [ + "5" + ], + "Content-Type": [ + "application/octet-stream" + ], + "Host": [ + "0awrsfc302.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd88fd-72d8964e1fed2bce3edd5aac" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "userId": "123" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test3/api/users/123/avatar", + "AccountId": "147997163238", + "ResourceId": "POST /test3/api/users/{userId}/avatar", + "Stage": "$default", + "RequestId": "JCJXri3_PHcEP_Q=", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test3/api/users/{userId}/avatar", + "HttpMethod": "POST", + "ApiId": "0awrsfc302", + "ExtendedRequestId": "JCJXri3_PHcEP_Q=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "0awrsfc302", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:15:25 \u002B0000", + "RequestTimeEpoch": 1744668925528, + "Status": null + }, + "Body": "AQIDBAU=", + "IsBase64Encoded": true +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json new file mode 100644 index 000000000..d47c345e0 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json @@ -0,0 +1,83 @@ +{ + "Resource": "/test4/api/users/{userId}/avatar", + "Path": "/test4/api/users/123/avatar", + "HttpMethod": "POST", + "Headers": { + "Content-Type": "application/octet-stream", + "Host": "4brwn090q0.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd8927-4b9cc8347ead8aa60c674ac2", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Type": [ + "application/octet-stream" + ], + "Host": [ + "4brwn090q0.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8927-4b9cc8347ead8aa60c674ac2" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "userId": "123" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test/test4/api/users/123/avatar", + "AccountId": "147997163238", + "ResourceId": "rz18ez", + "Stage": "test", + "RequestId": "7a1ab4cd-edd9-4437-86d3-7978341c597d", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": null, + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test4/api/users/{userId}/avatar", + "HttpMethod": "POST", + "ApiId": "4brwn090q0", + "ExtendedRequestId": "JCJePHSSPHcEtwQ=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "4brwn090q0.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "4brwn090q0", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:16:07 \u002B0000", + "RequestTimeEpoch": 1744668967561, + "Status": null + }, + "Body": "AQIDBAU=", + "IsBase64Encoded": true +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json new file mode 100644 index 000000000..e01088dfd --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 500, + "Content": "{\u0022message\u0022:\u0022Internal Server Error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJp2jd_vHcEPSQ=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json new file mode 100644 index 000000000..1a23816c0 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpvgQCvHcEPjA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json new file mode 100644 index 000000000..757c435e8 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 500, + "Content": "{\u0022message\u0022:\u0022Internal Server Error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpqjdkvHcESPQ=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json new file mode 100644 index 000000000..5c31c6d22 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 502, + "Content": "{\u0022message\u0022:\u0022Internal server error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "5f0c2904-275c-4054-9516-bfb8d083ca5c" + ], + "x-amz-apigw-id": [ + "JCJpsEPhPHcEYng=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8970-7b93429f14d1f5622f3dbbdd;Parent=1b82af92b8de065c;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json new file mode 100644 index 000000000..97d3d1175 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJp0hfdvHcEStw=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json new file mode 100644 index 000000000..515a0fc4d --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022name\u0022: \u0022John Doe\u0022, \u0022age\u0022:", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpejtwvHcEP4Q=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json new file mode 100644 index 000000000..56d2deed4 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "[1, 2, 3, 4, 5]", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpZjR6vHcEP8g=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "15" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json new file mode 100644 index 000000000..54ce49b8c --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "f85bec66-ed59-4668-a56e-ee22ffeb64b4" + ], + "x-amz-apigw-id": [ + "JCJpxEpoPHcENcQ=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8971-0b7317956f1709703a7ac1b6;Parent=7bf631ebae3cc567;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json new file mode 100644 index 000000000..ff75ba372 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022name\u0022: \u0022John Doe\u0022, \u0022age\u0022: 30}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpbg4wPHcEPeA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "31" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json new file mode 100644 index 000000000..575cac85b --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "true", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJplh_ePHcEP_Q=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "4" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json new file mode 100644 index 000000000..cb2a45beb --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpPi4DvHcEPVw=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "0" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json new file mode 100644 index 000000000..1ebd5e496 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Special \u0022quoted\u0022 text", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpXh5MvHcEP2Q=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "21" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json new file mode 100644 index 000000000..12a38b7fe --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "42", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpUgEovHcEPXQ=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "2" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json new file mode 100644 index 000000000..1421fc076 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpngwcPHcEP7A=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json new file mode 100644 index 000000000..e83bc3950 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpggYbvHcEQ_Q=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json new file mode 100644 index 000000000..643b81ffb --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "test", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:17:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCJpjjKCPHcEPYA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "4" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json new file mode 100644 index 000000000..f69857f2a --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "test", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:14 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInCh-qvHcEP1Q=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "4" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json new file mode 100644 index 000000000..14b85adc0 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "test", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:14 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "22da8529-3838-4358-af49-769f0e8a28d3" + ], + "x-amz-apigw-id": [ + "JCInFHSPvHcEbLw=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87c6-599b0807184cacba153a1a84;Parent=566cbcbec60f211c;Sampled=0;Lineage=1:d294b742:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "4" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json new file mode 100644 index 000000000..09f365cd5 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Test body", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCIn6iOMPHcEP2Q=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "9" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json new file mode 100644 index 000000000..380edca40 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "Test body", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:22 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "224e0b2e-0dfa-481a-ad65-b647686cb362" + ], + "x-amz-apigw-id": [ + "JCIoWGiIvHcEsxg=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87ce-39b57ec370e7a7551e8f43db;Parent=752c273a1dbf0dc3;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "9" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json new file mode 100644 index 000000000..40ab4ac07 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json @@ -0,0 +1,33 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Combined Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "X-Custom-Header": [ + "single-value" + ], + "Combined-Header": [ + "single-value", + "multi-value1", + "multi-value2" + ], + "X-Multi-Header": [ + "multi-value1", + "multi-value2" + ], + "Apigw-Requestid": [ + "JCInwiC6PHcEPqA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json new file mode 100644 index 000000000..7c13d3c95 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json @@ -0,0 +1,39 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Combined Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "81f577be-40b5-4090-b5fd-fbd5864d11de" + ], + "x-amz-apigw-id": [ + "JCIoNGABvHcEdvw=" + ], + "X-Custom-Header": [ + "single-value" + ], + "Combined-Header": [ + "multi-value1", + "multi-value2", + "single-value" + ], + "X-Multi-Header": [ + "multi-value1", + "multi-value2" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cd-7c1728c00ed2a9ab47410203;Parent=2c9d25f546eb4264;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json new file mode 100644 index 000000000..94a3d4335 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInsioPPHcEP-w=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json new file mode 100644 index 000000000..009f9a9c5 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "8ec8d88e-4536-4e8e-a5f2-28877a4cc5b2" + ], + "x-amz-apigw-id": [ + "JCIoIEenvHcEGNA=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cd-548ca2e2768cf411287e4266;Parent=3389559e9a470afb;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json new file mode 100644 index 000000000..cb2d3ef8b --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json @@ -0,0 +1,31 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Multiple Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Myheader": [ + "test,other" + ], + "Anotherheader": [ + "secondvalue" + ], + "Headername": [ + "headervalue", + "headervalue2" + ], + "Apigw-Requestid": [ + "JCInujOivHcEPVw=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json new file mode 100644 index 000000000..10c63f4de --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json @@ -0,0 +1,37 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Multiple Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "60a62529-4157-4038-a796-1c57440bc5f6" + ], + "anotherheader": [ + "secondvalue" + ], + "x-amz-apigw-id": [ + "JCIoKGHFPHcEaIQ=" + ], + "headername": [ + "headervalue", + "headervalue2" + ], + "myheader": [ + "test,other" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cd-619e118449cb17b736abd8bc;Parent=23e83a8204296606;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json new file mode 100644 index 000000000..441416758 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 500, + "Content": "{\u0022message\u0022:\u0022Internal Server Error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCIn1jYWPHcEPYA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json new file mode 100644 index 000000000..e84aace44 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 502, + "Content": "{\u0022message\u0022: \u0022Internal server error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:22 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "2f7d670c-f2d1-4b0b-b3fc-ebf72f7ef67a" + ], + "x-amzn-ErrorType": [ + "InternalServerErrorException" + ], + "x-amz-apigw-id": [ + "JCIoRE-lvHcEpYQ=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "36" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json new file mode 100644 index 000000000..e531a2263 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:18 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInpgsKvHcEP2A=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json new file mode 100644 index 000000000..d697e7420 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "d8da867e-ae50-4e05-83ce-e5165c9e9586" + ], + "x-amz-apigw-id": [ + "JCIoGGcWvHcEm5Q=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cd-7a12883c7a049d3c313ce630;Parent=5c509f06483696a4;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json new file mode 100644 index 000000000..edfd10e69 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInzjkJPHcEP8g=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json new file mode 100644 index 000000000..44ea21741 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:21 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "98e123eb-4ffc-42c3-b4e6-9223b85c852c" + ], + "x-amz-apigw-id": [ + "JCIoPGCVPHcEdvw=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cd-114aa6b332dc7ac812d45ba5;Parent=7d089a4e04c6b482;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json new file mode 100644 index 000000000..a3460a03e --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 201, + "Content": "{\u0022message\u0022:\u0022Created\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:17 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCIniiXWPHcEPHA=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "21" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json new file mode 100644 index 000000000..b50316d1c --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 201, + "Content": "{\u0022message\u0022:\u0022Created\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "a5e7a2f4-03ad-41a0-838a-ce70db8c1e6f" + ], + "x-amz-apigw-id": [ + "JCIn_HvOvHcEdIQ=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cc-469a8eac2157be907b932892;Parent=73bab1a764c16624;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "21" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json new file mode 100644 index 000000000..37dedd724 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json @@ -0,0 +1,24 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:17 GMT" + ], + "Connection": [ + "keep-alive" + ], + "X-Custom-Header": [ + "CustomValue" + ], + "Apigw-Requestid": [ + "JCInkj0BvHcEPwg=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json new file mode 100644 index 000000000..bac667913 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json @@ -0,0 +1,30 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "f373ffe9-0c95-4dea-939c-c4b4107f5b2b" + ], + "x-amz-apigw-id": [ + "JCIoBGy1vHcEByg=" + ], + "X-Custom-Header": [ + "CustomValue" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cc-1c44b97f31e2497b61a72ba5;Parent=24865536df2a4944;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json new file mode 100644 index 000000000..5620bf9b1 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json @@ -0,0 +1,25 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With MultiValueHeaders\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:17 GMT" + ], + "Connection": [ + "keep-alive" + ], + "X-Multi-Header": [ + "Value1", + "Value2" + ], + "Apigw-Requestid": [ + "JCInniZlPHcEP1g=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "36" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json new file mode 100644 index 000000000..10f458ffb --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json @@ -0,0 +1,31 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With MultiValueHeaders\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "4e98bdf1-03fa-4601-b886-5f8b40f4798e" + ], + "x-amz-apigw-id": [ + "JCIoDGzFPHcEDbA=" + ], + "X-Multi-Header": [ + "Value1", + "Value2" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cc-7da269a52a5e078b4c255580;Parent=5c6edcf395e1147f;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "36" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json new file mode 100644 index 000000000..393e55f08 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json @@ -0,0 +1,110 @@ +{ + "Resource": "/test1/api/users/{userId}/orders", + "Path": "/test1/api/users/123/orders", + "HttpMethod": "POST", + "Headers": { + "Content-Length": "0", + "Content-Type": "text/plain; charset=utf-8", + "Cookie": "session=abc123; theme=dark", + "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "User-Agent": "TestAgent", + "X-Amzn-Trace-Id": "Root=1-67fd8937-6cd643e155b4258a556982c5", + "X-Custom-Header": "value1", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Length": [ + "0" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Cookie": [ + "session=abc123; theme=dark" + ], + "Host": [ + "0awrsfc302.execute-api.us-west-2.amazonaws.com" + ], + "User-Agent": [ + "TestAgent" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8937-6cd643e155b4258a556982c5" + ], + "X-Custom-Header": [ + "value1" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": { + "status": "pending", + "tag": "urgent" + }, + "MultiValueQueryStringParameters": { + "status": [ + "pending" + ], + "tag": [ + "important", + "urgent" + ] + }, + "PathParameters": { + "userId": "123" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test1/api/users/123/orders", + "AccountId": "147997163238", + "ResourceId": "POST /test1/api/users/{userId}/orders", + "Stage": "$default", + "RequestId": "JCJgriq-vHcEPMg=", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "TestAgent", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test1/api/users/{userId}/orders", + "HttpMethod": "POST", + "ApiId": "0awrsfc302", + "ExtendedRequestId": "JCJgriq-vHcEPMg=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "0awrsfc302", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:16:23 \u002B0000", + "RequestTimeEpoch": 1744668983126, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json new file mode 100644 index 000000000..94fbc7955 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json @@ -0,0 +1,106 @@ +{ + "Resource": "/test1/api/users/{userId}/orders", + "Path": "/test1/api/users/123/orders", + "HttpMethod": "POST", + "Headers": { + "Content-Type": "text/plain; charset=utf-8", + "Cookie": "session=abc123; theme=dark", + "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "User-Agent": "TestAgent", + "X-Amzn-Trace-Id": "Root=1-67fd87f5-7643e6a875203f06341af04f", + "X-Custom-Header": "value1", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Cookie": [ + "session=abc123; theme=dark" + ], + "Host": [ + "s902u1zkkl.execute-api.us-west-2.amazonaws.com" + ], + "User-Agent": [ + "TestAgent" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87f5-7643e6a875203f06341af04f" + ], + "X-Custom-Header": [ + "value1" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": { + "status": "pending", + "tag": "urgent" + }, + "MultiValueQueryStringParameters": { + "status": [ + "pending" + ], + "tag": [ + "important", + "urgent" + ] + }, + "PathParameters": { + "userId": "123" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test/test1/api/users/123/orders", + "AccountId": "147997163238", + "ResourceId": "06oou2", + "Stage": "test", + "RequestId": "4acd49e9-9210-4d04-8e04-0f26a4e92537", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "TestAgent", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test1/api/users/{userId}/orders", + "HttpMethod": "POST", + "ApiId": "s902u1zkkl", + "ExtendedRequestId": "JCIudEUfPHcEhog=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "s902u1zkkl", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:11:01 \u002B0000", + "RequestTimeEpoch": 1744668661718, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json new file mode 100644 index 000000000..ac0c38898 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:17 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInggGjPHcEP3w=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json new file mode 100644 index 000000000..c0664b8fb --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:20 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "8af0f750-fdfc-4b2e-bf85-0218623df93e" + ], + "x-amz-apigw-id": [ + "JCIn8ELXPHcEC1A=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87cc-09a86408172acd0726c798d5;Parent=136d0e43afa6f0c4;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json new file mode 100644 index 000000000..cd95b17ec --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json @@ -0,0 +1,88 @@ +{ + "Resource": "/test5/api/users/{username}/orders/{orderName}", + "Path": "/test5/api/users/****%20Doe/orders/Summer%20Sale%202023", + "HttpMethod": "POST", + "Headers": { + "Content-Length": "0", + "Content-Type": "text/plain; charset=utf-8", + "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd895b-766061a83ad2b27b1782b470", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Length": [ + "0" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "0awrsfc302.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd895b-766061a83ad2b27b1782b470" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "orderName": "Summer Sale 2023", + "username": "**** Doe" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test5/api/users/**** Doe/orders/Summer Sale 2023", + "AccountId": "147997163238", + "ResourceId": "POST /test5/api/users/{username}/orders/{orderName}", + "Stage": "$default", + "RequestId": "JCJmXjUAPHcEP4w=", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test5/api/users/{username}/orders/{orderName}", + "HttpMethod": "POST", + "ApiId": "0awrsfc302", + "ExtendedRequestId": "JCJmXjUAPHcEP4w=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "0awrsfc302", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:16:59 \u002B0000", + "RequestTimeEpoch": 1744669019524, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json new file mode 100644 index 000000000..99b10d245 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json @@ -0,0 +1,84 @@ +{ + "Resource": "/test5/api/users/{username}/orders/{orderName}", + "Path": "/test5/api/users/****%20Doe/orders/Summer%20Sale%202023", + "HttpMethod": "POST", + "Headers": { + "Content-Type": "text/plain; charset=utf-8", + "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd8860-650d70a10ef73c6b16106e8d", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "s902u1zkkl.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8860-650d70a10ef73c6b16106e8d" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "username": "****%20Doe", + "orderName": "Summer%20Sale%202023" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test/test5/api/users/****%20Doe/orders/Summer%20Sale%202023", + "AccountId": "147997163238", + "ResourceId": "g76y15", + "Stage": "test", + "RequestId": "dbcb1121-909c-4d1a-aff3-958e94138b79", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": null, + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test5/api/users/{username}/orders/{orderName}", + "HttpMethod": "POST", + "ApiId": "s902u1zkkl", + "ExtendedRequestId": "JCI_JHpQvHcEhVw=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "s902u1zkkl", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:12:48 \u002B0000", + "RequestTimeEpoch": 1744668768586, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json new file mode 100644 index 000000000..29b5060c2 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json @@ -0,0 +1,88 @@ +{ + "Resource": "/test6/api/products/{productName}/reviews/{reviewTitle}", + "Path": "/test6/api/products/%E2%98%95%20Coffee/reviews/%F0%9F%98%8A%20Happy", + "HttpMethod": "POST", + "Headers": { + "Content-Length": "0", + "Content-Type": "text/plain; charset=utf-8", + "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd896c-70b58b4501a8b49c5ef26f03", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Length": [ + "0" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "0awrsfc302.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd896c-70b58b4501a8b49c5ef26f03" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "productName": "\u2615 Coffee", + "reviewTitle": "\uD83D\uDE0A Happy" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test6/api/products/\u2615 Coffee/reviews/\uD83D\uDE0A Happy", + "AccountId": "147997163238", + "ResourceId": "POST /test6/api/products/{productName}/reviews/{reviewTitle}", + "Stage": "$default", + "RequestId": "JCJpDi3HPHcESow=", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test6/api/products/{productName}/reviews/{reviewTitle}", + "HttpMethod": "POST", + "ApiId": "0awrsfc302", + "ExtendedRequestId": "JCJpDi3HPHcESow=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "0awrsfc302", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:17:16 \u002B0000", + "RequestTimeEpoch": 1744669036726, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json new file mode 100644 index 000000000..662d5282b --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json @@ -0,0 +1,84 @@ +{ + "Resource": "/test6/api/products/{productName}/reviews/{reviewTitle}", + "Path": "/test6/api/products/%E2%98%95%20Coffee/reviews/%F0%9F%98%8A%20Happy", + "HttpMethod": "POST", + "Headers": { + "Content-Type": "text/plain; charset=utf-8", + "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd8892-563c02fe4dcb438f51739a1b", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "s902u1zkkl.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8892-563c02fe4dcb438f51739a1b" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": null, + "MultiValueQueryStringParameters": null, + "PathParameters": { + "productName": "%E2%98%95%20Coffee", + "reviewTitle": "%F0%9F%98%8A%20Happy" + }, + "StageVariables": null, + "RequestContext": { + "Path": "/test/test6/api/products/%E2%98%95%20Coffee/reviews/%F0%9F%98%8A%20Happy", + "AccountId": "147997163238", + "ResourceId": "hafaxt", + "Stage": "test", + "RequestId": "5005340a-1104-4054-98d0-afda9e163eb1", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": null, + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test6/api/products/{productName}/reviews/{reviewTitle}", + "HttpMethod": "POST", + "ApiId": "s902u1zkkl", + "ExtendedRequestId": "JCJG5GmOvHcEK7g=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "s902u1zkkl", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:13:38 \u002B0000", + "RequestTimeEpoch": 1744668818115, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json new file mode 100644 index 000000000..c685151c4 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json @@ -0,0 +1,96 @@ +{ + "Resource": "/test4/api/search", + "Path": "/test4/api/search", + "HttpMethod": "POST", + "Headers": { + "Content-Length": "0", + "Content-Type": "text/plain; charset=utf-8", + "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd894d-3c512d985fc0f8aa38cbeaac", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Length": [ + "0" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "0awrsfc302.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd894d-3c512d985fc0f8aa38cbeaac" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": { + "q": "Hello World", + "tag": ".NET Core" + }, + "MultiValueQueryStringParameters": { + "q": [ + "Hello World" + ], + "tag": [ + "C# Programming", + ".NET Core" + ] + }, + "PathParameters": null, + "StageVariables": null, + "RequestContext": { + "Path": "/test4/api/search", + "AccountId": "147997163238", + "ResourceId": "POST /test4/api/search", + "Stage": "$default", + "RequestId": "JCJkHhmUPHcEPXA=", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": "", + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test4/api/search", + "HttpMethod": "POST", + "ApiId": "0awrsfc302", + "ExtendedRequestId": "JCJkHhmUPHcEPXA=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "0awrsfc302", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:16:45 \u002B0000", + "RequestTimeEpoch": 1744669005175, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json new file mode 100644 index 000000000..c4e154cb2 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json @@ -0,0 +1,92 @@ +{ + "Resource": "/test4/api/search", + "Path": "/test4/api/search", + "HttpMethod": "POST", + "Headers": { + "Content-Type": "text/plain; charset=utf-8", + "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "X-Amzn-Trace-Id": "Root=1-67fd8822-75aa8f5e7a30566958eef084", + "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-Port": "443", + "X-Forwarded-Proto": "https" + }, + "MultiValueHeaders": { + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Host": [ + "s902u1zkkl.execute-api.us-west-2.amazonaws.com" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd8822-75aa8f5e7a30566958eef084" + ], + "X-Forwarded-For": [ + "141.149.44.5" + ], + "X-Forwarded-Port": [ + "443" + ], + "X-Forwarded-Proto": [ + "https" + ] + }, + "QueryStringParameters": { + "q": "Hello World", + "tag": ".NET Core" + }, + "MultiValueQueryStringParameters": { + "q": [ + "Hello World" + ], + "tag": [ + "C# Programming", + ".NET Core" + ] + }, + "PathParameters": null, + "StageVariables": null, + "RequestContext": { + "Path": "/test/test4/api/search", + "AccountId": "147997163238", + "ResourceId": "3x3a3q", + "Stage": "test", + "RequestId": "bc5e4f00-8cfb-4473-83c7-e6e1735ee418", + "Identity": { + "CognitoIdentityPoolId": null, + "AccountId": null, + "CognitoIdentityId": null, + "Caller": null, + "ApiKey": null, + "ApiKeyId": null, + "AccessKey": null, + "SourceIp": "141.149.44.5", + "CognitoAuthenticationType": null, + "CognitoAuthenticationProvider": null, + "UserArn": null, + "UserAgent": null, + "User": null, + "ClientCert": null + }, + "ResourcePath": "/test4/api/search", + "HttpMethod": "POST", + "ApiId": "s902u1zkkl", + "ExtendedRequestId": "JCI1hFtPPHcEDUw=", + "ConnectionId": null, + "ConnectedAt": 0, + "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "s902u1zkkl", + "EventType": null, + "MessageId": null, + "RouteKey": null, + "Authorizer": null, + "OperationName": null, + "Error": null, + "IntegrationLatency": null, + "MessageDirection": null, + "RequestTime": "14/Apr/2025:22:11:46 \u002B0000", + "RequestTimeEpoch": 1744668706991, + "Status": null + }, + "Body": null, + "IsBase64Encoded": false +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json new file mode 100644 index 000000000..8068c33c7 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:19 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCIn4gyyPHcEP6g=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json new file mode 100644 index 000000000..80ad1c99b --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:22 GMT" + ], + "Connection": [ + "keep-alive" + ], + "x-amzn-RequestId": [ + "244fe60b-0535-4085-ad6a-eddd235e4a6d" + ], + "x-amz-apigw-id": [ + "JCIoUEtDPHcEsnA=" + ], + "X-Amzn-Trace-Id": [ + "Root=1-67fd87ce-3a13e69076acb7a07dacd9c3;Parent=48a841fdc26e5fb0;Sampled=0;Lineage=1:6e5eb7d9:0" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json new file mode 100644 index 000000000..9f9b75be9 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json @@ -0,0 +1,44 @@ +{ + "Version": "2.0", + "RouteKey": "POST /test11/api/users/{userId}/avatar", + "RawPath": "/test11/api/users/123/avatar", + "RawQueryString": "", + "Cookies": null, + "Headers": { + "content-length": "5", + "content-type": "application/octet-stream", + "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "x-amzn-trace-id": "Root=1-67fd88b8-2f95df5a03c1bc3a6168b6d8", + "x-forwarded-for": "141.149.44.5", + "x-forwarded-port": "443", + "x-forwarded-proto": "https" + }, + "QueryStringParameters": null, + "RequestContext": { + "AccountId": "147997163238", + "ApiId": "7y6qzvvbof", + "Authorizer": null, + "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "7y6qzvvbof", + "Http": { + "Method": "POST", + "Path": "/test11/api/users/123/avatar", + "Protocol": "HTTP/1.1", + "SourceIp": "141.149.44.5", + "UserAgent": "" + }, + "RequestId": "JCJM3j95PHcEJHg=", + "RouteId": null, + "RouteKey": "POST /test11/api/users/{userId}/avatar", + "Stage": "$default", + "Time": "14/Apr/2025:22:14:16 \u002B0000", + "TimeEpoch": 1744668856359, + "Authentication": null + }, + "Body": "AQIDBAU=", + "PathParameters": { + "userId": "123" + }, + "IsBase64Encoded": true, + "StageVariables": null +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json new file mode 100644 index 000000000..0003327f9 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Hello, World!", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:16 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInWhFRvHcEJdA=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "13" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json new file mode 100644 index 000000000..d65a3460f --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 201, + "Content": "{\u0022key\u0022:\u0022value\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:16 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInbgLtPHcEJIQ=" + ], + "Content-Type": [ + "application/xml" + ], + "Content-Length": [ + "15" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json new file mode 100644 index 000000000..13b6a0bc0 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json @@ -0,0 +1,27 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:16 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Myheader": [ + "test,shouldhavesecondvalue" + ], + "Anotherheader": [ + "secondvalue" + ], + "Apigw-Requestid": [ + "JCInYgIKPHcEJbQ=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json new file mode 100644 index 000000000..cf9ba6661 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 500, + "Content": "{\u0022message\u0022:\u0022Internal Server Error\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:15 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInMhIpPHcEJ3w=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "35" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json new file mode 100644 index 000000000..7cd0fbb9e --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "Test body", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:16 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCIndgObPHcEJVQ=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "9" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json new file mode 100644 index 000000000..1171b40c0 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, API Gateway v2!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:16 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInTjApPHcEJhw=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "36" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json new file mode 100644 index 000000000..c7a0e3901 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, API Gateway v2!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:15 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInRg47PHcEJXQ=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "36" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json new file mode 100644 index 000000000..3bbd2e6ad --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 201, + "Content": "{\u0022message\u0022:\u0022Created\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:15 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInKgOZPHcEJhg=" + ], + "Content-Type": [ + "text/plain; charset=utf-8" + ], + "Content-Length": [ + "21" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json new file mode 100644 index 000000000..6e8a971f2 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json @@ -0,0 +1,24 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022With Headers\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:15 GMT" + ], + "Connection": [ + "keep-alive" + ], + "X-Custom-Header": [ + "CustomValue" + ], + "Apigw-Requestid": [ + "JCInPj6JPHcEJow=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "26" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json new file mode 100644 index 000000000..28deb4c69 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json @@ -0,0 +1,53 @@ +{ + "Version": "2.0", + "RouteKey": "POST /test9/api/users/{userId}/orders", + "RawPath": "/test9/api/users/123/orders", + "RawQueryString": "status=pending\u0026tag=important\u0026tag=urgent", + "Cookies": [ + "session=abc123", + "theme=dark" + ], + "Headers": { + "accept": "text/html, application/json", + "content-length": "0", + "content-type": "text/plain; charset=utf-8", + "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "user-agent": "TestAgent", + "x-amzn-trace-id": "Root=1-67fd88a4-127eb8e773d2bb6f7df47ab6", + "x-custom-header": "value1", + "x-forwarded-for": "141.149.44.5", + "x-forwarded-port": "443", + "x-forwarded-proto": "https" + }, + "QueryStringParameters": { + "status": "pending", + "tag": "important,urgent" + }, + "RequestContext": { + "AccountId": "147997163238", + "ApiId": "7y6qzvvbof", + "Authorizer": null, + "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "7y6qzvvbof", + "Http": { + "Method": "POST", + "Path": "/test9/api/users/123/orders", + "Protocol": "HTTP/1.1", + "SourceIp": "141.149.44.5", + "UserAgent": "TestAgent" + }, + "RequestId": "JCJJxhz4PHcEJgQ=", + "RouteId": null, + "RouteKey": "POST /test9/api/users/{userId}/orders", + "Stage": "$default", + "Time": "14/Apr/2025:22:13:56 \u002B0000", + "TimeEpoch": 1744668836573, + "Authentication": null + }, + "Body": null, + "PathParameters": { + "userId": "123" + }, + "IsBase64Encoded": false, + "StageVariables": null +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json new file mode 100644 index 000000000..0434de255 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json @@ -0,0 +1,21 @@ +{ + "StatusCode": 200, + "Content": "{\u0022message\u0022:\u0022Hello, World!\u0022}", + "Headers": { + "Date": [ + "Mon, 14 Apr 2025 22:10:14 GMT" + ], + "Connection": [ + "keep-alive" + ], + "Apigw-Requestid": [ + "JCInHg8UPHcEJsA=" + ], + "Content-Type": [ + "application/json" + ], + "Content-Length": [ + "27" + ] + } +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json new file mode 100644 index 000000000..c2f9a0312 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json @@ -0,0 +1,45 @@ +{ + "Version": "2.0", + "RouteKey": "POST /test13/api/users/{username}/orders/{orderName}", + "RawPath": "/test13/api/users/**** Doe/orders/Summer Sale 2023", + "RawQueryString": "", + "Cookies": null, + "Headers": { + "content-length": "0", + "content-type": "text/plain; charset=utf-8", + "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "x-amzn-trace-id": "Root=1-67fd88db-518e8b296009540c739c0ca7", + "x-forwarded-for": "141.149.44.5", + "x-forwarded-port": "443", + "x-forwarded-proto": "https" + }, + "QueryStringParameters": null, + "RequestContext": { + "AccountId": "147997163238", + "ApiId": "7y6qzvvbof", + "Authorizer": null, + "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "7y6qzvvbof", + "Http": { + "Method": "POST", + "Path": "/test13/api/users/**** Doe/orders/Summer Sale 2023", + "Protocol": "HTTP/1.1", + "SourceIp": "141.149.44.5", + "UserAgent": "" + }, + "RequestId": "JCJSViW5PHcESow=", + "RouteId": null, + "RouteKey": "POST /test13/api/users/{username}/orders/{orderName}", + "Stage": "$default", + "Time": "14/Apr/2025:22:14:51 \u002B0000", + "TimeEpoch": 1744668891302, + "Authentication": null + }, + "Body": null, + "PathParameters": { + "orderName": "Summer Sale 2023", + "username": "**** Doe" + }, + "IsBase64Encoded": false, + "StageVariables": null +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json new file mode 100644 index 000000000..f96252162 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json @@ -0,0 +1,45 @@ +{ + "Version": "2.0", + "RouteKey": "POST /test14/api/products/{productName}/reviews/{reviewTitle}", + "RawPath": "/test14/api/products/\u2615 Coffee/reviews/\uD83D\uDE0A Happy", + "RawQueryString": "", + "Cookies": null, + "Headers": { + "content-length": "0", + "content-type": "text/plain; charset=utf-8", + "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "x-amzn-trace-id": "Root=1-67fd88e9-487b329f49f6278e32bb642c", + "x-forwarded-for": "141.149.44.5", + "x-forwarded-port": "443", + "x-forwarded-proto": "https" + }, + "QueryStringParameters": null, + "RequestContext": { + "AccountId": "147997163238", + "ApiId": "7y6qzvvbof", + "Authorizer": null, + "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "7y6qzvvbof", + "Http": { + "Method": "POST", + "Path": "/test14/api/products/\u2615 Coffee/reviews/\uD83D\uDE0A Happy", + "Protocol": "HTTP/1.1", + "SourceIp": "141.149.44.5", + "UserAgent": "" + }, + "RequestId": "JCJUkhKBvHcESVw=", + "RouteId": null, + "RouteKey": "POST /test14/api/products/{productName}/reviews/{reviewTitle}", + "Stage": "$default", + "Time": "14/Apr/2025:22:15:05 \u002B0000", + "TimeEpoch": 1744668905625, + "Authentication": null + }, + "Body": null, + "PathParameters": { + "productName": "\u2615 Coffee", + "reviewTitle": "\uD83D\uDE0A Happy" + }, + "IsBase64Encoded": false, + "StageVariables": null +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json new file mode 100644 index 000000000..3ab34cfdc --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json @@ -0,0 +1,45 @@ +{ + "Version": "2.0", + "RouteKey": "POST /test12/api/search", + "RawPath": "/test12/api/search", + "RawQueryString": "q=Hello%20World\u0026tag=C%23%20Programming\u0026tag=.NET%20Core", + "Cookies": null, + "Headers": { + "content-length": "0", + "content-type": "text/plain; charset=utf-8", + "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "x-amzn-trace-id": "Root=1-67fd88cb-4981526a50466e9f2be0fbed", + "x-forwarded-for": "141.149.44.5", + "x-forwarded-port": "443", + "x-forwarded-proto": "https" + }, + "QueryStringParameters": { + "q": "Hello World", + "tag": "C# Programming,.NET Core" + }, + "RequestContext": { + "AccountId": "147997163238", + "ApiId": "7y6qzvvbof", + "Authorizer": null, + "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "DomainPrefix": "7y6qzvvbof", + "Http": { + "Method": "POST", + "Path": "/test12/api/search", + "Protocol": "HTTP/1.1", + "SourceIp": "141.149.44.5", + "UserAgent": "" + }, + "RequestId": "JCJP4iwYPHcEJgQ=", + "RouteId": null, + "RouteKey": "POST /test12/api/search", + "Stage": "$default", + "Time": "14/Apr/2025:22:14:35 \u002B0000", + "TimeEpoch": 1744668875623, + "Authentication": null + }, + "Body": null, + "PathParameters": null, + "IsBase64Encoded": false, + "StageVariables": null +} \ No newline at end of file From 5bafbb0844709ad7193f1e1fa384df8d1290ca6c Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 19:16:16 -0400 Subject: [PATCH 2/9] remove uneeded code --- ...on.Lambda.TestTool.IntegrationTests.csproj | 4 - .../ApiGatewayIntegrationTestCollection.cs | 13 - .../ApiGatewayIntegrationTestFixture.cs | 283 ----------------- ...atewayResponseExtensionsAdditionalTests.cs | 68 +---- .../ApiGatewayResponseExtensionsTests.cs | 38 +-- .../Helpers/ApiGatewayHelper.cs | 223 -------------- .../Helpers/ApiGatewayTestHelper.cs | 39 +-- .../Helpers/CloudFormationHelper.cs | 51 ---- .../Helpers/RetryHelper.cs | 27 -- .../Helpers/snapshot/SnapshotTestHelper.cs | 1 - .../HttpContextExtensionsTests.cs | 193 +----------- ...nvokeResponseExtensionsIntegrationTests.cs | 49 +-- ...ponse_HttpV1APIGatewayV1DecodesBase64.json | 21 -- ...esponse_RestAPIGatewayV1DecodesBase64.json | 27 -- .../TestRoutes.cs | 67 ---- .../cloudformation-template-apigateway.yaml | 288 ------------------ .../HttpContextTestCases.cs | 1 - 17 files changed, 52 insertions(+), 1341 deletions(-) delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestCollection.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/CloudFormationHelper.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/RetryHelper.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/TestRoutes.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/cloudformation-template-apigateway.yaml diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj index a7753846f..9b7481c06 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj @@ -40,10 +40,6 @@ - - - - diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestCollection.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestCollection.cs deleted file mode 100644 index dc628d9b5..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestCollection.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Xunit; - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - [CollectionDefinition("ApiGateway Integration Tests")] - public class ApiGatewayIntegrationTestCollection : ICollectionFixture - { - - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs deleted file mode 100644 index dd50f9796..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayIntegrationTestFixture.cs +++ /dev/null @@ -1,283 +0,0 @@ -// 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 Amazon.Lambda.TestTool.Models; -using System.Reflection; -using Xunit; - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - public class ApiGatewayIntegrationTestFixture : IAsyncLifetime - { - private readonly Dictionary _testRoutes; - - public CloudFormationHelper CloudFormationHelper { get; private set; } - public ApiGatewayHelper ApiGatewayHelper { get; private set; } - public ApiGatewayTestHelper ApiGatewayTestHelper { get; private set; } - - public string StackName { get; private set; } - - // Main API Gateway IDs and Base URLs - public string MainRestApiId { get; private set; } - public string MainHttpApiV1Id { get; private set; } - public string MainHttpApiV2Id { get; private set; } - public string BinaryMediaTypeRestApiId { get; private set; } // this is the rest api that has binary media types of */* enabled - - public string MainRestApiBaseUrl { get; private set; } - public string MainHttpApiV1BaseUrl { get; private set; } - public string MainHttpApiV2BaseUrl { get; private set; } - public string BinaryMediaTypeRestApiBaseUrl { get; private set; } - - // Lambda Function ARNs - public string ParseAndReturnBodyLambdaFunctionArn { get; private set; } - public string ReturnRawBodyLambdaFunctionArn { get; private set; } - public string ReturnFullEventLambdaFunctionArn { get; private set; } - public string ReturnDecodedParseBinLambdaFunctionArn { 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(); - _testRoutes = new Dictionary(); - - StackName = string.Empty; - MainRestApiId = string.Empty; - MainHttpApiV1Id = string.Empty; - MainHttpApiV2Id = string.Empty; - BinaryMediaTypeRestApiId = string.Empty; - MainRestApiBaseUrl = string.Empty; - MainHttpApiV1BaseUrl = string.Empty; - MainHttpApiV2BaseUrl = string.Empty; - BinaryMediaTypeRestApiBaseUrl = string.Empty; - ParseAndReturnBodyLambdaFunctionArn = string.Empty; - ReturnRawBodyLambdaFunctionArn = string.Empty; - ReturnFullEventLambdaFunctionArn = string.Empty; - ReturnDecodedParseBinLambdaFunctionArn = string.Empty; - } - - public void RegisterTestRoute(string routeId, TestRouteConfig config) - { - if (string.IsNullOrEmpty(routeId)) - { - throw new ArgumentNullException(nameof(routeId)); - } - - if (config == null) - { - throw new ArgumentNullException(nameof(config)); - } - - if (string.IsNullOrEmpty(config.Path)) - { - throw new ArgumentException("Route path cannot be empty", nameof(config)); - } - - if (string.IsNullOrEmpty(config.HttpMethod)) - { - throw new ArgumentException("HTTP method cannot be empty", nameof(config)); - } - - if (string.IsNullOrEmpty(config.LambdaFunctionArn)) - { - throw new ArgumentException("Lambda function ARN cannot be empty", nameof(config)); - } - - _testRoutes[routeId] = config; - } - - public string GetRouteUrl(string baseUrl, string routeId) - { - if (!_testRoutes.TryGetValue(routeId, out var config)) - { - throw new KeyNotFoundException($"Route {routeId} not found"); - } - return baseUrl.TrimEnd('/') + config.Path; - } - - public string GetAppropriateBaseUrl(ApiGatewayType gatewayType) - { - return gatewayType switch - { - ApiGatewayType.Rest => MainRestApiBaseUrl, - ApiGatewayType.RestWithBinarySupport => BinaryMediaTypeRestApiBaseUrl, - ApiGatewayType.HttpV1 => MainHttpApiV1BaseUrl, - ApiGatewayType.HttpV2 => MainHttpApiV2BaseUrl, - _ => throw new ArgumentException($"Unsupported gateway type: {gatewayType}") - }; - } - - public string GetAppropriateApiId(ApiGatewayType gatewayType) - { - return gatewayType switch - { - ApiGatewayType.Rest => MainRestApiId, - ApiGatewayType.RestWithBinarySupport => BinaryMediaTypeRestApiId, - ApiGatewayType.HttpV1 => MainHttpApiV1Id, - ApiGatewayType.HttpV2 => MainHttpApiV2Id, - _ => throw new ArgumentException($"Unsupported gateway type: {gatewayType}") - }; - } - - public static ApiGatewayEmulatorMode GetEmulatorMode(ApiGatewayType gatewayType) - { - return gatewayType switch - { - ApiGatewayType.Rest or ApiGatewayType.RestWithBinarySupport => ApiGatewayEmulatorMode.Rest, - ApiGatewayType.HttpV1 => ApiGatewayEmulatorMode.HttpV1, - ApiGatewayType.HttpV2 => ApiGatewayEmulatorMode.HttpV2, - _ => throw new ArgumentException($"Unsupported gateway type: {gatewayType}") - }; - } - - - 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(); - - // Register all test routes using RegisterTestRoute - foreach (var (routeId, config) in TestRoutes.GetDefaultRoutes(this)) - { - RegisterTestRoute(routeId, config); - } - - // Setup all routes - await SetupTestRoutes(); - await WaitForRoutesAvailability(); - } - - private async Task SetupTestRoutes() - { - foreach (var (routeId, config) in _testRoutes) - { - await ApiGatewayHelper.AddRouteToRestApi( - MainRestApiId, - config.LambdaFunctionArn, - config.Path, - config.HttpMethod); - - await ApiGatewayHelper.AddRouteToHttpApi( - MainHttpApiV1Id, - config.LambdaFunctionArn, - "1.0", - config.Path, - config.HttpMethod); - - await ApiGatewayHelper.AddRouteToHttpApi( - MainHttpApiV2Id, - config.LambdaFunctionArn, - "2.0", - config.Path, - config.HttpMethod); - - await ApiGatewayHelper.AddRouteToRestApi( - BinaryMediaTypeRestApiId, - config.LambdaFunctionArn, - config.Path, - config.HttpMethod); - } - } - - private async Task WaitForRoutesAvailability() - { - foreach (var config in _testRoutes.Values) - { - var restUrl = MainRestApiBaseUrl.TrimEnd('/') + config.Path; - var httpV1Url = MainHttpApiV1BaseUrl.TrimEnd('/') + config.Path; - var httpV2Url = MainHttpApiV2BaseUrl.TrimEnd('/') + config.Path; - var binaryUrl = BinaryMediaTypeRestApiBaseUrl.TrimEnd('/') + config.Path; - - await ApiGatewayHelper.WaitForApiAvailability(BinaryMediaTypeRestApiId, binaryUrl, false); - await ApiGatewayHelper.WaitForApiAvailability(MainRestApiId, restUrl, false); - await ApiGatewayHelper.WaitForApiAvailability(MainHttpApiV1Id, httpV1Url, true); - await ApiGatewayHelper.WaitForApiAvailability(MainHttpApiV2Id, httpV2Url, true); - } - } - - 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() - { - MainRestApiId = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainRestApiId"); - MainHttpApiV1Id = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainHttpApiV1Id"); - MainHttpApiV2Id = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainHttpApiV2Id"); - BinaryMediaTypeRestApiId = await CloudFormationHelper.GetOutputValueAsync(StackName, "BinaryMediaTypeRestApiId"); - - MainRestApiBaseUrl = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainRestApiBaseUrl"); - MainHttpApiV1BaseUrl = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainHttpApiV1BaseUrl"); - MainHttpApiV2BaseUrl = await CloudFormationHelper.GetOutputValueAsync(StackName, "MainHttpApiV2BaseUrl"); - BinaryMediaTypeRestApiBaseUrl = await CloudFormationHelper.GetOutputValueAsync(StackName, "BinaryMediaTypeRestApiBaseUrl"); - - ParseAndReturnBodyLambdaFunctionArn = await CloudFormationHelper.GetOutputValueAsync(StackName, "ParseAndReturnBodyLambdaFunctionArn"); - ReturnRawBodyLambdaFunctionArn = await CloudFormationHelper.GetOutputValueAsync(StackName, "ReturnRawBodyLambdaFunctionArn"); - ReturnFullEventLambdaFunctionArn = await CloudFormationHelper.GetOutputValueAsync(StackName, "ReturnFullEventLambdaFunctionArn"); - ReturnDecodedParseBinLambdaFunctionArn = await CloudFormationHelper.GetOutputValueAsync(StackName, "ReturnDecodedParseBinLambdaFunctionArn"); - } - - public async Task DisposeAsync() - { - await CloudFormationHelper.DeleteStackAsync(StackName); - } - } - - public enum ApiGatewayType - { - Rest, - RestWithBinarySupport, - HttpV1, - HttpV2 - } - - public class ApiGatewayTestConfig - { - public required string RouteId { get; init; } - public required ApiGatewayType GatewayType { get; init; } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs index 4f305d7c4..714d4d37e 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs @@ -3,35 +3,15 @@ using Amazon.Lambda.APIGatewayEvents; using Microsoft.AspNetCore.Http; -using System.Text.Json; using Amazon.Lambda.TestTool.Extensions; using Amazon.Lambda.TestTool.Models; using System.Text; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; using Xunit; namespace Amazon.Lambda.TestTool.IntegrationTests { - [Collection("ApiGateway Integration Tests")] public class ApiGatewayResponseExtensionsAdditionalTests { - private readonly ApiGatewayIntegrationTestFixture _fixture; - private readonly HttpClient _httpClient; - private readonly SnapshotTestHelper _snapshots; - - - public ApiGatewayResponseExtensionsAdditionalTests(ApiGatewayIntegrationTestFixture fixture) - { - _fixture = fixture; - _httpClient = new HttpClient(); - _snapshots = new SnapshotTestHelper(new JsonSerializerOptions - { - WriteIndented = true, - Converters = { new HttpResponseMessageConverter() } - } - ); - } - [Fact] public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() { @@ -46,26 +26,11 @@ public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() httpContext.Response.Body = new MemoryStream(); await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.Rest); - if (_snapshots.IsUpdatingSnapshots) - { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.RestWithBinarySupport); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.DecodeParseBinary); - var actualResponse = await _httpClient.PostAsync( - url, - new StringContent(JsonSerializer.Serialize(testResponse)), - new CancellationTokenSource(5000).Token); - - await _snapshots.SaveSnapshot(actualResponse, nameof(ToHttpResponse_RestAPIGatewayV1DecodesBase64)); - } - else - { - var snapshot = await _snapshots.LoadSnapshot( - nameof(ToHttpResponse_RestAPIGatewayV1DecodesBase64)); + httpContext.Response.Body.Position = 0; - Assert.Equal(200, (int)snapshot.StatusCode); - var content = await snapshot.Content.ReadAsStringAsync(); - Assert.Equal("test", content); - } + Assert.Equal(200, (int)httpContext.Response.StatusCode); + var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); + Assert.Equal("test", content); } [Fact] @@ -78,27 +43,16 @@ public async Task ToHttpResponse_HttpV1APIGatewayV1DecodesBase64() IsBase64Encoded = true }; - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV1); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); + var httpContext = new DefaultHttpContext(); + httpContext.Response.Body = new MemoryStream(); + await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.HttpV1); - if (_snapshots.IsUpdatingSnapshots) - { - var actualResponse = await _httpClient.PostAsync( - url, - new StringContent(JsonSerializer.Serialize(testResponse)), - new CancellationTokenSource(5000).Token); + httpContext.Response.Body.Position = 0; - await _snapshots.SaveSnapshot(actualResponse, nameof(ToHttpResponse_HttpV1APIGatewayV1DecodesBase64)); - } - else - { - var snapshot = await _snapshots.LoadSnapshot( - nameof(ToHttpResponse_HttpV1APIGatewayV1DecodesBase64)); + Assert.Equal(200, (int)httpContext.Response.StatusCode); + var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); + Assert.Equal("test", content); - Assert.Equal(200, (int)snapshot.StatusCode); - var content = await snapshot.Content.ReadAsStringAsync(); - Assert.Equal("test", content); - } } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs index e33b50269..aed687175 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using Amazon.Lambda.APIGatewayEvents; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; using Amazon.Lambda.TestTool.Tests.Common; using Xunit; @@ -9,57 +10,42 @@ namespace Amazon.Lambda.TestTool.IntegrationTests { - [Collection("ApiGateway Integration Tests")] public class ApiGatewayResponseExtensionsTests { - private readonly ApiGatewayIntegrationTestFixture _fixture; - - public ApiGatewayResponseExtensionsTests(ApiGatewayIntegrationTestFixture fixture) - { - _fixture = fixture; - } + private ApiGatewayTestHelper _helper = new(); [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] + [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] public async Task IntegrationTest_APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.Rest); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - await RunV1Test(testCase, url, ApiGatewayEmulatorMode.Rest, testName); + await RunV1Test(testCase, ApiGatewayEmulatorMode.Rest, testName); } [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] + [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] public async Task IntegrationTest_APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV1); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - await RunV1Test(testCase, url, ApiGatewayEmulatorMode.HttpV1, testName); + await RunV1Test(testCase, ApiGatewayEmulatorMode.HttpV1, testName); } [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] + [MemberData(nameof(V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) { - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; Assert.NotNull(testResponse); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, url, testName); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, testName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); await testCase.IntegrationAssertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); } - private async Task RunV1Test(ApiGatewayResponseTestCase testCase, string apiUrl, ApiGatewayEmulatorMode emulatorMode, string testName) + private async Task RunV1Test(ApiGatewayResponseTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) { var testResponse = testCase.Response as APIGatewayProxyResponse; Assert.NotNull(testResponse); var testCaseName = testName + emulatorMode; - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, apiUrl, emulatorMode, testCaseName); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, emulatorMode, testCaseName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); await testCase.IntegrationAssertions(actualResponse, emulatorMode); } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs deleted file mode 100644 index f0bdb3c72..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayHelper.cs +++ /dev/null @@ -1,223 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Amazon.APIGateway; -using Amazon.ApiGatewayV2; -using Amazon.APIGateway.Model; -using Amazon.ApiGatewayV2.Model; -using System.Net; - -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers -{ - public class ApiGatewayHelper - { - private readonly IAmazonAPIGateway _apiGatewayV1Client; - private readonly IAmazonApiGatewayV2 _apiGatewayV2Client; - - public ApiGatewayHelper(IAmazonAPIGateway apiGatewayV1Client, IAmazonApiGatewayV2 apiGatewayV2Client) - { - _apiGatewayV1Client = apiGatewayV1Client; - _apiGatewayV2Client = apiGatewayV2Client; - } - - public async Task WaitForApiAvailability(string apiId, string apiUrl, bool isHttpApi, int maxWaitTimeSeconds = 60) - { - var startTime = DateTime.UtcNow; - var successStartTime = DateTime.UtcNow; - var requiredSuccessDuration = TimeSpan.FromSeconds(10); - bool hasBeenSuccessful = false; - - while ((DateTime.UtcNow - startTime).TotalSeconds < maxWaitTimeSeconds) - { - try - { - // Check if the API exists - if (isHttpApi) - { - var response = await _apiGatewayV2Client.GetApiAsync(new GetApiRequest { ApiId = apiId }); - if (response.ApiEndpoint == null) continue; - } - else - { - var response = await _apiGatewayV1Client.GetRestApiAsync(new GetRestApiRequest { RestApiId = apiId }); - if (response.Id == null) continue; - } - - // Try to make a request to the API - using (var httpClient = new HttpClient()) - { - var response = await httpClient.PostAsync(apiUrl, new StringContent("{}")); - - // Check if we get a successful response - if (response.StatusCode != HttpStatusCode.Forbidden && response.StatusCode != HttpStatusCode.NotFound) - { - if (!hasBeenSuccessful) - { - successStartTime = DateTime.UtcNow; - hasBeenSuccessful = true; - } - - if ((DateTime.UtcNow - successStartTime) >= requiredSuccessDuration) - { - return; // API has been responding successfully for at least 10 seconds - } - } - else - { - // Reset the success timer if we get a non-successful response - hasBeenSuccessful = false; - Console.WriteLine($"API responded with status code: {response.StatusCode}"); - } - } - } - catch (Amazon.ApiGatewayV2.Model.NotFoundException) when (isHttpApi) - { - // HTTP API not found yet, continue waiting - hasBeenSuccessful = false; - } - catch (Amazon.APIGateway.Model.NotFoundException) when (!isHttpApi) - { - // REST API not found yet, continue waiting - hasBeenSuccessful = false; - } - catch (Exception ex) - { - // Log unexpected exceptions and reset success timer - Console.WriteLine($"Unexpected error while checking API availability: {ex.Message}"); - hasBeenSuccessful = false; - } - await Task.Delay(1000); // Wait for 1 second before checking again - } - throw new TimeoutException($"API {apiId} did not become consistently available within {maxWaitTimeSeconds} seconds"); - } - - - public async Task AddRouteToRestApi(string restApiId, string lambdaArn, string route = "/test", string httpMethod = "ANY") - { - // Get all resources and find the root resource - var resources = await _apiGatewayV1Client.GetResourcesAsync(new GetResourcesRequest { RestApiId = restApiId }); - var rootResource = resources.Items.First(r => r.Path == "/"); - var rootResourceId = rootResource.Id; - - // Split the route into parts and create each part - var routeParts = route.Trim('/').Split('/'); - string currentPath = ""; - string parentResourceId = rootResourceId; - - foreach (var part in routeParts) - { - currentPath += "/" + part; - - // Check if the resource already exists - var existingResource = resources.Items.FirstOrDefault(r => r.Path == currentPath); - if (existingResource == null) - { - // Create the resource if it doesn't exist - var createResourceResponse = await _apiGatewayV1Client.CreateResourceAsync(new CreateResourceRequest - { - RestApiId = restApiId, - ParentId = parentResourceId, - PathPart = part - }); - parentResourceId = createResourceResponse.Id; - } - else - { - parentResourceId = existingResource.Id; - } - } - - // Create the method and integration - await _apiGatewayV1Client.PutMethodAsync(new PutMethodRequest - { - RestApiId = restApiId, - ResourceId = parentResourceId, - HttpMethod = httpMethod, - AuthorizationType = "NONE" - }); - - await _apiGatewayV1Client.PutIntegrationAsync(new PutIntegrationRequest - { - RestApiId = restApiId, - ResourceId = parentResourceId, - HttpMethod = httpMethod, - Type = Amazon.APIGateway.IntegrationType.AWS_PROXY, - IntegrationHttpMethod = "POST", - Uri = $"arn:aws:apigateway:{_apiGatewayV1Client.Config.RegionEndpoint.SystemName}:lambda:path/2015-03-31/functions/{lambdaArn}/invocations" - }); - - // Create and wait for deployment - var deploymentResponse = await _apiGatewayV1Client.CreateDeploymentAsync(new Amazon.APIGateway.Model.CreateDeploymentRequest - { - RestApiId = restApiId, - StageName = "test" - }); - - return $"https://{restApiId}.execute-api.{_apiGatewayV1Client.Config.RegionEndpoint.SystemName}.amazonaws.com/test{route}"; - } - - public async Task AddRouteToHttpApi(string httpApiId, string lambdaArn, string version, string route = "/test", string httpMethod = "ANY") - { - var createIntegrationResponse = await _apiGatewayV2Client.CreateIntegrationAsync(new CreateIntegrationRequest - { - ApiId = httpApiId, - IntegrationType = Amazon.ApiGatewayV2.IntegrationType.AWS_PROXY, - IntegrationUri = lambdaArn, - PayloadFormatVersion = version, - IntegrationMethod = "POST" - }); - string integrationId = createIntegrationResponse.IntegrationId; - - // Split the route into parts and create each part - var routeParts = route.Trim('/').Split('/'); - var currentPath = ""; - foreach (var part in routeParts) - { - currentPath += "/" + part; - await _apiGatewayV2Client.CreateRouteAsync(new CreateRouteRequest - { - ApiId = httpApiId, - RouteKey = $"{httpMethod} {currentPath}", - Target = $"integrations/{integrationId}" - }); - } - - // Create the final route (if it's not already created) - if (currentPath != "/" + route.Trim('/')) - { - await _apiGatewayV2Client.CreateRouteAsync(new CreateRouteRequest - { - ApiId = httpApiId, - RouteKey = $"{httpMethod} {route}", - Target = $"integrations/{integrationId}" - }); - } - - // Create and wait for deployment - var deployment = await _apiGatewayV2Client.CreateDeploymentAsync(new Amazon.ApiGatewayV2.Model.CreateDeploymentRequest - { - ApiId = httpApiId - }); - - // Create stage if it doesn't exist - try - { - await _apiGatewayV2Client.CreateStageAsync(new Amazon.ApiGatewayV2.Model.CreateStageRequest - { - ApiId = httpApiId, - StageName = "$default", - AutoDeploy = true - }); - } - catch (Amazon.ApiGatewayV2.Model.ConflictException) - { - // Stage already exists, continue - } - - var url = $"https://{httpApiId}.execute-api.{_apiGatewayV2Client.Config.RegionEndpoint.SystemName}.amazonaws.com{route}"; - return url ; - } - - - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs index aa26f335d..132f6eccf 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -using System.Runtime.CompilerServices; using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; @@ -28,7 +27,6 @@ public ApiGatewayTestHelper() public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( APIGatewayProxyResponse testResponse, - string apiUrl, ApiGatewayEmulatorMode emulatorMode, string testName) { @@ -38,23 +36,7 @@ public ApiGatewayTestHelper() await testResponse.ToHttpResponseAsync(testResponseHttpContext, emulatorMode); HttpResponseMessage actualResponse; - if (_snapshots.IsUpdatingSnapshots) - { - // When updating snapshots, we need to make the real API call - using var httpClient = new HttpClient(); - var serialized = JsonSerializer.Serialize(testResponse); - actualResponse = await httpClient.PostAsync( - apiUrl, - new StringContent(serialized), - new CancellationTokenSource(5000).Token); - - await _snapshots.SaveSnapshot(actualResponse, testName); - } - else - { - // Load existing snapshot and verify - actualResponse = await _snapshots.LoadSnapshot(testName); - } + actualResponse = await _snapshots.LoadSnapshot(testName); return (actualResponse, testResponseHttpContext.Response); @@ -62,7 +44,6 @@ public ApiGatewayTestHelper() public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( APIGatewayHttpApiV2ProxyResponse testResponse, - string apiUrl, string testName) { // Generate the expected response using ToHttpResponseAsync @@ -71,23 +52,7 @@ public ApiGatewayTestHelper() await testResponse.ToHttpResponseAsync(testResponseHttpContext); HttpResponseMessage actualResponse; - if (_snapshots.IsUpdatingSnapshots) - { - // When updating snapshots, make the real API call - using var httpClient = new HttpClient(); - var serialized = JsonSerializer.Serialize(testResponse); - actualResponse = await httpClient.PostAsync( - apiUrl, - new StringContent(serialized), - new CancellationTokenSource(5000).Token); - - await _snapshots.SaveSnapshot(actualResponse, testName); - } - else - { - // Load existing snapshot - actualResponse = await _snapshots.LoadSnapshot(testName); - } + actualResponse = await _snapshots.LoadSnapshot(testName); return (actualResponse, testResponseHttpContext.Response); } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/CloudFormationHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/CloudFormationHelper.cs deleted file mode 100644 index 1fc1a1ee6..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/CloudFormationHelper.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Amazon.CloudFormation; -using Amazon.CloudFormation.Model; - -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers -{ - public class CloudFormationHelper - { - private readonly IAmazonCloudFormation _cloudFormationClient; - - public CloudFormationHelper(IAmazonCloudFormation cloudFormationClient) - { - _cloudFormationClient = cloudFormationClient; - } - - public async Task CreateStackAsync(string stackName, string templateBody) - { - var response = await _cloudFormationClient.CreateStackAsync(new CreateStackRequest - { - StackName = stackName, - TemplateBody = templateBody, - Capabilities = new List { "CAPABILITY_IAM" }, - Tags = new List - { - new Tag { Key = "aws-tests", Value = typeof(CloudFormationHelper).FullName }, - new Tag { Key = "aws-repo", Value = "aws-lambda-dotnet" } - } - }); - return response.StackId; - } - - public async Task GetStackStatusAsync(string stackName) - { - var response = await _cloudFormationClient.DescribeStacksAsync(new DescribeStacksRequest { StackName = stackName }); - return response.Stacks[0].StackStatus; - } - - public async Task DeleteStackAsync(string stackName) - { - await _cloudFormationClient.DeleteStackAsync(new DeleteStackRequest { StackName = stackName }); - } - - public async Task GetOutputValueAsync(string stackName, string outputKey) - { - var response = await _cloudFormationClient.DescribeStacksAsync(new DescribeStacksRequest { StackName = stackName }); - return response.Stacks[0].Outputs.FirstOrDefault(o => o.OutputKey == outputKey)?.OutputValue ?? string.Empty; - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/RetryHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/RetryHelper.cs deleted file mode 100644 index f6e5e18e4..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/RetryHelper.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers -{ - public class RetryHelper - { - public static async Task RetryOperation(Func> operation, int maxRetries = 3, int delayMilliseconds = 20000) - { - for (int i = 0; i < maxRetries; i++) - { - try - { - return await operation(); - } - catch (Exception ex) when (i < maxRetries - 1) - { - Console.WriteLine($"Attempt {i + 1} failed: {ex.Message}. Retrying in {delayMilliseconds}ms..."); - await Task.Delay(delayMilliseconds); - } - } - - // If we've exhausted all retries, run one last time and let any exception propagate - return await operation(); - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs index e275c0e0e..a82a20fa6 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs @@ -8,7 +8,6 @@ public class SnapshotTestHelper { private readonly string _snapshotDirectory; private readonly JsonSerializerOptions _serializerOptions; - public bool IsUpdatingSnapshots => true; public SnapshotTestHelper(JsonSerializerOptions? serializerOptions = null, string snapshotDirectory = "Snapshots") { diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs index c545ac677..335e4e800 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 using System.Net; -using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; using Amazon.Lambda.TestTool.Models; @@ -11,63 +10,44 @@ using Microsoft.Extensions.Primitives; using Xunit; using static Amazon.Lambda.TestTool.Tests.Common.HttpContextTestCases; -using System.Runtime.CompilerServices; using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; namespace Amazon.Lambda.TestTool.IntegrationTests { - [Collection("ApiGateway Integration Tests")] public class HttpContextExtensionsTests { - private readonly ApiGatewayIntegrationTestFixture _fixture; private readonly SnapshotTestHelper _snapshots; - public HttpContextExtensionsTests(ApiGatewayIntegrationTestFixture fixture) + public HttpContextExtensionsTests() { - _fixture = fixture; _snapshots = new SnapshotTestHelper(); } [Theory] - [MemberData(nameof(HttpContextTestCases.V1TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCase testCase) { var testCaseName = testName + ApiGatewayEmulatorMode.Rest; - return RunApiGatewayTest(testCase, new ApiGatewayTestConfig - { - RouteId = TestRoutes.Ids.ReturnFullEvent, - GatewayType = ApiGatewayType.Rest - }, - testCaseName); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, testCaseName); } [Theory] - [MemberData(nameof(HttpContextTestCases.V1TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) { var testCaseName = testName + ApiGatewayEmulatorMode.HttpV1; - return RunApiGatewayTest(testCase, new ApiGatewayTestConfig - { - RouteId = TestRoutes.Ids.ReturnFullEvent, - GatewayType = ApiGatewayType.HttpV1 - }, - testCaseName); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, testCaseName); } [Theory] - [MemberData(nameof(HttpContextTestCases.V2TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V2TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] public Task IntegrationTest_APIGatewayV2(string testName, HttpContextTestCase testCase) { - return RunApiGatewayTest(testCase, new ApiGatewayTestConfig - { - RouteId = TestRoutes.Ids.ReturnFullEvent, - GatewayType = ApiGatewayType.HttpV2 - }, - testName); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV2, testName); } [Fact] @@ -100,14 +80,7 @@ public Task BinaryContentHttpV1() } }; - return RunApiGatewayTest( - testCase, - new ApiGatewayTestConfig - { - RouteId = TestRoutes.Ids.ReturnFullEvent, - GatewayType = ApiGatewayType.HttpV1 - }, - nameof(BinaryContentHttpV1)); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, nameof(BinaryContentHttpV1)); } [Fact] @@ -140,38 +113,25 @@ public Task BinaryContentRest() } }; - return RunApiGatewayTest(testCase, new ApiGatewayTestConfig - { - RouteId = TestRoutes.Ids.ReturnFullEvent, - GatewayType = ApiGatewayType.RestWithBinarySupport - }, - nameof(BinaryContentRest)); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, nameof(BinaryContentRest)); } - private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayTestConfig config, string testName) where T : class + private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) where T : class { - var baseUrl = _fixture.GetAppropriateBaseUrl(config.GatewayType); - var apiId = _fixture.GetAppropriateApiId(config.GatewayType); - var emulatorMode = ApiGatewayIntegrationTestFixture.GetEmulatorMode(config.GatewayType); - - - Func> converter = config.GatewayType switch + Func> converter = emulatorMode switch { - ApiGatewayType.Rest or ApiGatewayType.RestWithBinarySupport => + ApiGatewayEmulatorMode.Rest => async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.Rest), - ApiGatewayType.HttpV1 => + ApiGatewayEmulatorMode.HttpV1 => async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.HttpV1), - ApiGatewayType.HttpV2 => + ApiGatewayEmulatorMode.HttpV2 => async (context, cfg) => (T)(object)await context.ToApiGatewayHttpV2Request(cfg), - _ => throw new ArgumentException($"Unsupported gateway type: {config.GatewayType}") + _ => throw new ArgumentException($"Unsupported gateway type: {emulatorMode}") }; await RunApiGatewayTestInternal( testCase, - baseUrl, - apiId, - config.RouteId, converter, emulatorMode, testName); @@ -179,104 +139,16 @@ await RunApiGatewayTestInternal( private async Task RunApiGatewayTestInternal( HttpContextTestCase testCase, - string baseUrl, - string apiId, - string routeId, Func> toApiGatewayRequest, ApiGatewayEmulatorMode emulatorMode, string testName) where T : class { - // Get the route config which has the path prefix - var routeConfig = TestRoutes.GetDefaultRoutes(_fixture)[routeId]; - T actualApiGatewayRequest; - - if (_snapshots.IsUpdatingSnapshots) - { - // Create the route for this specific test - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - await _fixture.ApiGatewayHelper.AddRouteToRestApi( - apiId, - routeConfig.LambdaFunctionArn, - testCase.ApiGatewayRouteConfig.Path, - testCase.ApiGatewayRouteConfig.HttpMethod - ); - } - else // HTTP API v1 or v2 - { - await _fixture.ApiGatewayHelper.AddRouteToHttpApi( - apiId, - routeConfig.LambdaFunctionArn, - emulatorMode == ApiGatewayEmulatorMode.HttpV2 ? "2.0" : "1.0", - testCase.ApiGatewayRouteConfig.Path, - testCase.ApiGatewayRouteConfig.HttpMethod - ); - } - - var httpClient = new HttpClient(); - var actualPath = ResolveActualPath(testCase.ApiGatewayRouteConfig.Path, testCase.HttpContext.Request.Path.Value ?? ""); - - var fullUrl = baseUrl.TrimEnd('/') + actualPath + testCase.HttpContext.Request.QueryString.Value; - - // Wait for the API to be available - await _fixture.ApiGatewayHelper.WaitForApiAvailability(apiId, fullUrl, emulatorMode != ApiGatewayEmulatorMode.Rest); - - // Create and send the HTTP request - var httpRequest = CreateHttpRequestMessage(testCase.HttpContext, fullUrl); - - // Send request and get response - var response = await httpClient.SendAsync(httpRequest); - var responseContent = await response.Content.ReadAsStringAsync(); - - // Verify response - Assert.Equal(200, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - - actualApiGatewayRequest = JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - - await _snapshots.SaveSnapshot(actualApiGatewayRequest, testName); - - } - else - { - actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); - - } - + actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); var expectedApiGatewayRequest = await toApiGatewayRequest(testCase.HttpContext, testCase.ApiGatewayRouteConfig); - CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest); - testCase.Assertions(actualApiGatewayRequest!, emulatorMode); - await Task.Delay(1000); // Small delay between requests - } - - private string ResolveActualPath(string routeWithPlaceholders, string actualPath) - { - var routeParts = routeWithPlaceholders.Split('/'); - var actualParts = actualPath.Split('/'); - - if (routeParts.Length != actualParts.Length) - { - throw new ArgumentException("Route and actual path have different number of segments"); - } - - var resolvedParts = new List(); - for (int i = 0; i < routeParts.Length; i++) - { - if (routeParts[i].StartsWith("{") && routeParts[i].EndsWith("}")) - { - resolvedParts.Add(actualParts[i]); - } - else - { - resolvedParts.Add(routeParts[i]); - } - } - - return string.Join("/", resolvedParts); } private void CompareApiGatewayRequests(T expected, T actual) where T : class? @@ -406,38 +278,5 @@ private void CompareRequestContexts(APIGatewayHttpApiV2ProxyRequest.ProxyRequest Assert.Equal(expected.Http.Protocol, actual.Http.Protocol); Assert.Equal(expected.Http.UserAgent, actual.Http.UserAgent); } - - private HttpRequestMessage CreateHttpRequestMessage(HttpContext context, string fullUrl) - { - var request = context.Request; - var httpRequest = new HttpRequestMessage(new HttpMethod(request.Method), fullUrl); - - foreach (var header in request.Headers) - { - httpRequest.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); - } - - if (request.ContentLength > 0) - { - var bodyStream = new MemoryStream(); - request.Body.CopyTo(bodyStream); - bodyStream.Position = 0; - httpRequest.Content = new StreamContent(bodyStream); - - // Set Content-Type if present in the original request - if (request.ContentType != null) - { - httpRequest.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(request.ContentType); - } - } - else - { - httpRequest.Content = new StringContent(string.Empty); - } - - httpRequest.Version = HttpVersion.Version11; - - return httpRequest; - } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs index 09ded4c46..91fc86926 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs @@ -7,6 +7,7 @@ using System.Text; using System.Text.Json; using Amazon.Lambda.TestTool.Extensions; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Xunit; namespace Amazon.Lambda.TestTool.IntegrationTests; @@ -21,26 +22,10 @@ namespace Amazon.Lambda.TestTool.IntegrationTests; /// that match the actual API Gateway behavior. This approach allows us to verify the correctness of our /// conversion methods within the constraints of not having access to AWS's internal conversion process. /// -[Collection("ApiGateway Integration Tests")] public class InvokeResponseExtensionsIntegrationTests { - private readonly ApiGatewayIntegrationTestFixture _fixture; - public InvokeResponseExtensionsIntegrationTests(ApiGatewayIntegrationTestFixture fixture) - { - _fixture = fixture; - } - - private ApiGatewayType GetGatewayType(ApiGatewayEmulatorMode emulatorMode) - { - return emulatorMode switch - { - ApiGatewayEmulatorMode.Rest => ApiGatewayType.Rest, - ApiGatewayEmulatorMode.HttpV1 => ApiGatewayType.HttpV1, - ApiGatewayEmulatorMode.HttpV2 => ApiGatewayType.HttpV2, - _ => throw new ArgumentException($"Unsupported emulator mode: {emulatorMode}") - }; - } + private readonly ApiGatewayTestHelper _helper = new(); [Theory] [InlineData(ApiGatewayEmulatorMode.Rest)] @@ -65,10 +50,8 @@ public async Task ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversio var testName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + emulatorMode; // Assert - var baseUrl = _fixture.GetAppropriateBaseUrl(GetGatewayType(emulatorMode)); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode, testName); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); } [Fact] @@ -90,10 +73,8 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirect var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); // Assert - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); } [Theory] @@ -116,9 +97,7 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); Assert.Contains(expectedErrorMessage, convertedResponse.Body); - var baseUrl = _fixture.GetAppropriateBaseUrl(GetGatewayType(emulatorMode)); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, _) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, emulatorMode, testName); + var (actualResponse, _) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); Assert.Equal(expectedStatusCode, (int)actualResponse.StatusCode); var content = await actualResponse.Content.ReadAsStringAsync(); Assert.Contains(expectedErrorMessage, content); @@ -180,11 +159,8 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); Assert.Equal("application/json", actualConvertedResponse.Headers["Content-Type"]); - // Verify against actual API Gateway behavior - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(actualConvertedResponse, url, testCaseName); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(actualConvertedResponse, testCaseName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); // Additional checks for API Gateway specific behavior Assert.Equal(200, (int)actualResponse.StatusCode); @@ -211,11 +187,8 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsIn Assert.Equal("{\"message\":\"Internal Server Error\"}", convertedResponse.Body); Assert.Equal("application/json", convertedResponse.Headers["Content-Type"]); - // Verify against actual API Gateway behavior - var baseUrl = _fixture.GetAppropriateBaseUrl(ApiGatewayType.HttpV2); - var url = _fixture.GetRouteUrl(baseUrl, TestRoutes.Ids.ParseAndReturnBody); - var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(convertedResponse, url, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); - await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); // Additional checks for API Gateway specific behavior Assert.Equal(500, (int)actualResponse.StatusCode); diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json deleted file mode 100644 index f69857f2a..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_HttpV1APIGatewayV1DecodesBase64.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "StatusCode": 200, - "Content": "test", - "Headers": { - "Date": [ - "Mon, 14 Apr 2025 22:10:14 GMT" - ], - "Connection": [ - "keep-alive" - ], - "Apigw-Requestid": [ - "JCInCh-qvHcEP1Q=" - ], - "Content-Type": [ - "text/plain; charset=utf-8" - ], - "Content-Length": [ - "4" - ] - } -} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json deleted file mode 100644 index 14b85adc0..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToHttpResponse_RestAPIGatewayV1DecodesBase64.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "StatusCode": 200, - "Content": "test", - "Headers": { - "Date": [ - "Mon, 14 Apr 2025 22:10:14 GMT" - ], - "Connection": [ - "keep-alive" - ], - "x-amzn-RequestId": [ - "22da8529-3838-4358-af49-769f0e8a28d3" - ], - "x-amz-apigw-id": [ - "JCInFHSPvHcEbLw=" - ], - "X-Amzn-Trace-Id": [ - "Root=1-67fd87c6-599b0807184cacba153a1a84;Parent=566cbcbec60f211c;Sampled=0;Lineage=1:d294b742:0" - ], - "Content-Type": [ - "application/json" - ], - "Content-Length": [ - "4" - ] - } -} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/TestRoutes.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/TestRoutes.cs deleted file mode 100644 index cf888d22e..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/TestRoutes.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - public class TestRouteConfig - { - public required string Path { get; set; } - public required string HttpMethod { get; set; } - public required string LambdaFunctionArn { get; set; } - public required string Description { get; set; } - } - - public static class TestRoutes - { - public static class Ids - { - public const string ParseAndReturnBody = "ParseAndReturnBody"; - public const string ReturnRawBody = "ReturnRawBody"; - public const string ReturnFullEvent = "ReturnFullEvent"; - public const string DecodeParseBinary = "BinaryMediaType"; - } - - public static class Paths - { - public const string ParseAndReturnBody = "/parse-and-return"; - public const string ReturnRawBody = "/return-raw"; - public const string ReturnFullEvent = "/return-full"; - public const string BinaryMediaType = "/binary"; - } - - public static Dictionary GetDefaultRoutes(ApiGatewayIntegrationTestFixture fixture) - { - return new Dictionary - { - [Ids.ParseAndReturnBody] = new TestRouteConfig - { - Path = Paths.ParseAndReturnBody, - HttpMethod = "POST", - LambdaFunctionArn = fixture.ParseAndReturnBodyLambdaFunctionArn, - Description = "Test parsing and returning body", - }, - [Ids.ReturnRawBody] = new TestRouteConfig - { - Path = Paths.ReturnRawBody, - HttpMethod = "POST", - LambdaFunctionArn = fixture.ReturnRawBodyLambdaFunctionArn, - Description = "Test returning raw body", - }, - [Ids.ReturnFullEvent] = new TestRouteConfig - { - Path = Paths.ReturnFullEvent, - HttpMethod = "POST", - LambdaFunctionArn = fixture.ReturnFullEventLambdaFunctionArn, - Description = "Test returning full event", - }, - [Ids.DecodeParseBinary] = new TestRouteConfig - { - Path = Paths.BinaryMediaType, - HttpMethod = "POST", - LambdaFunctionArn = fixture.ReturnDecodedParseBinLambdaFunctionArn, - Description = "Test binary media type handling", - } - }; - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/cloudformation-template-apigateway.yaml b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/cloudformation-template-apigateway.yaml deleted file mode 100644 index df37f013b..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/cloudformation-template-apigateway.yaml +++ /dev/null @@ -1,288 +0,0 @@ -AWSTemplateFormatVersion: '2010-09-09' -Description: 'CloudFormation template for API Gateway and Lambda integration tests' - -Resources: - # Lambda Functions - ParseAndReturnBodyLambdaFunction: - Type: 'AWS::Lambda::Function' - Properties: - FunctionName: !Sub '${AWS::StackName}-ParseAndReturnBodyFunction' - Handler: index.handler - Role: !GetAtt LambdaExecutionRole.Arn - Code: - ZipFile: | - exports.handler = async (event) => { - return JSON.parse(event.body); - }; - Runtime: nodejs20.x - - ReturnDecodedParseBinLambdaFunction: - Type: 'AWS::Lambda::Function' - Properties: - FunctionName: !Sub '${AWS::StackName}-ReturnDecodedParseBinFunction' - Handler: index.handler - Role: !GetAtt LambdaExecutionRole.Arn - Code: - ZipFile: | - exports.handler = async (event) => { - const decodedBody = atob(event.body); - const parsedBody = JSON.parse(decodedBody.toString('utf8')); - return parsedBody; - }; - Runtime: nodejs20.x - - ReturnRawBodyLambdaFunction: - Type: 'AWS::Lambda::Function' - Properties: - FunctionName: !Sub '${AWS::StackName}-ReturnRawBodyFunction' - Handler: index.handler - Role: !GetAtt LambdaExecutionRole.Arn - Code: - ZipFile: | - exports.handler = async (event, context, callback) => { - console.log(event); - callback(null, event.body); - }; - Runtime: nodejs20.x - - ReturnFullEventLambdaFunction: - Type: 'AWS::Lambda::Function' - Properties: - FunctionName: !Sub '${AWS::StackName}-ReturnFullEventFunction' - Handler: index.handler - Role: !GetAtt LambdaExecutionRole.Arn - Code: - ZipFile: | - exports.handler = async (event) => { - return { - statusCode: 200, - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(event) - }; - }; - Runtime: nodejs20.x - - # IAM Role for Lambda Functions - LambdaExecutionRole: - Type: 'AWS::IAM::Role' - Properties: - AssumeRolePolicyDocument: - Version: '2012-10-17' - Statement: - - Effect: Allow - Principal: - Service: lambda.amazonaws.com - Action: 'sts:AssumeRole' - ManagedPolicyArns: - - 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole' - - # Main REST API Gateway (without binary media types) - MainRestApi: - Type: 'AWS::ApiGateway::RestApi' - Properties: - Name: !Sub '${AWS::StackName}-MainRestAPI' - EndpointConfiguration: - Types: - - REGIONAL - - # Main HTTP API v1 - MainHttpApiV1: - Type: 'AWS::ApiGatewayV2::Api' - Properties: - Name: !Sub '${AWS::StackName}-MainHttpAPIv1' - ProtocolType: HTTP - - # Main HTTP API v2 - MainHttpApiV2: - Type: 'AWS::ApiGatewayV2::Api' - Properties: - Name: !Sub '${AWS::StackName}-MainHttpAPIv2' - ProtocolType: HTTP - - # Special REST API for binary media type tests - BinaryMediaTypeRestApi: - Type: 'AWS::ApiGateway::RestApi' - Properties: - Name: !Sub '${AWS::StackName}-BinaryMediaTypeRestApi' - EndpointConfiguration: - Types: - - REGIONAL - BinaryMediaTypes: - - '*/*' - - # Add a dummy root method for the initial deployment - MainRestApiRootMethod: - Type: 'AWS::ApiGateway::Method' - Properties: - HttpMethod: GET - ResourceId: !GetAtt MainRestApi.RootResourceId - RestApiId: !Ref MainRestApi - AuthorizationType: NONE - Integration: - Type: AWS_PROXY - IntegrationHttpMethod: POST - Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ReturnFullEventLambdaFunction.Arn}/invocations' - - MainRestApiDeployment: - Type: 'AWS::ApiGateway::Deployment' - DependsOn: MainRestApiRootMethod # Add explicit dependency - Properties: - RestApiId: !Ref MainRestApi - StageName: 'test' - - MainHttpV1Stage: - Type: 'AWS::ApiGatewayV2::Stage' - Properties: - ApiId: !Ref MainHttpApiV1 - StageName: '$default' - AutoDeploy: true - - MainHttpV2Stage: - Type: 'AWS::ApiGatewayV2::Stage' - Properties: - ApiId: !Ref MainHttpApiV2 - StageName: '$default' - AutoDeploy: true - - # Lambda Permissions for REST API - LambdaPermissionMainRestApi: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ParseAndReturnBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainRestApi}/*' - - LambdaPermissionMainRestApi2: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnRawBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainRestApi}/*' - - LambdaPermissionMainRestApi3: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnFullEventLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainRestApi}/*' - - # Lambda Permissions for HTTP API v1 - LambdaPermissionMainHttpApiV1: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ParseAndReturnBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV1}/*' - - LambdaPermissionMainHttpApiV12: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnRawBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV1}/*' - - LambdaPermissionMainHttpApiV13: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnFullEventLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV1}/*' - - # Lambda Permissions for HTTP API v2 - LambdaPermissionMainHttpApiV2: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ParseAndReturnBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV2}/*' - - LambdaPermissionMainHttpApiV22: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnRawBodyLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV2}/*' - - LambdaPermissionMainHttpApiV23: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnFullEventLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MainHttpApiV2}/*' - - # Lambda Permissions for Binary Media Type REST API - LambdaPermissionBinaryMediaTypeRestApi: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnDecodedParseBinLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${BinaryMediaTypeRestApi}/*' - - LambdaPermissionBinaryMediaTypeRestApi2: - Type: 'AWS::Lambda::Permission' - Properties: - Action: 'lambda:InvokeFunction' - FunctionName: !GetAtt ReturnFullEventLambdaFunction.Arn - Principal: apigateway.amazonaws.com - SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${BinaryMediaTypeRestApi}/*' - -Outputs: - MainRestApiId: - Description: 'ID of the Main REST API' - Value: !Ref MainRestApi - - MainRestApiBaseUrl: - Description: 'Base URL of the Main REST API' - Value: !Sub 'https://${MainRestApi}.execute-api.${AWS::Region}.amazonaws.com/test' - - MainHttpApiV1Id: - Description: 'ID of the Main HTTP API v1' - Value: !Ref MainHttpApiV1 - - MainHttpApiV1BaseUrl: - Description: 'Base URL of the Main HTTP API v1' - Value: !Sub 'https://${MainHttpApiV1}.execute-api.${AWS::Region}.amazonaws.com' - - MainHttpApiV2Id: - Description: 'ID of the Main HTTP API v2' - Value: !Ref MainHttpApiV2 - - MainHttpApiV2BaseUrl: - Description: 'Base URL of the Main HTTP API v2' - Value: !Sub 'https://${MainHttpApiV2}.execute-api.${AWS::Region}.amazonaws.com' - - BinaryMediaTypeRestApiId: - Description: 'ID of the Binary Media Type REST API' - Value: !Ref BinaryMediaTypeRestApi - - BinaryMediaTypeRestApiBaseUrl: - Description: 'Base URL of the Binary Media Type REST API' - Value: !Sub 'https://${BinaryMediaTypeRestApi}.execute-api.${AWS::Region}.amazonaws.com/test' - - ParseAndReturnBodyLambdaFunctionArn: - Description: 'ARN of the Parse and Return Body Lambda Function' - Value: !GetAtt ParseAndReturnBodyLambdaFunction.Arn - - ReturnRawBodyLambdaFunctionArn: - Description: 'ARN of the Return Raw Body Lambda Function' - Value: !GetAtt ReturnRawBodyLambdaFunction.Arn - - ReturnFullEventLambdaFunctionArn: - Description: 'ARN of the Return Full Event Lambda Function' - Value: !GetAtt ReturnFullEventLambdaFunction.Arn - - ReturnDecodedParseBinLambdaFunctionArn: - Description: 'ARN of the Return Decoded Parse Bin Lambda Function' - Value: !GetAtt ReturnDecodedParseBinLambdaFunction.Arn diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs index 22b20a93e..aeb5fdc14 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -using System.Net.Http; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Models; using Microsoft.AspNetCore.Http; From 3dd0501ca944b63e2e66b24e9581d0a16b415fee Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 19:45:23 -0400 Subject: [PATCH 3/9] move snapshot IT tests to unit tests --- ...on.Lambda.TestTool.IntegrationTests.csproj | 4 - ...atewayResponseExtensionsAdditionalTests.cs | 58 --- .../ApiGatewayResponseExtensionsTests.cs | 52 --- .../HttpContextExtensionsTests.cs | 282 ------------- ...nvokeResponseExtensionsIntegrationTests.cs | 199 --------- .../ApiGatewayTestHelper.cs | 2 +- .../ApiGatewayResponseExtensionsTests.cs | 95 +++-- .../ApiGatewayResponseTestCases.cs | 213 ++-------- .../Extensions/HttpContextExtensionsTests.cs | 390 ++++++++++-------- .../Extensions}/HttpContextTestCases.cs | 2 +- .../InvokeResponseExtensionsTests.cs | 224 ++++++++-- .../SnapshotHelper}/ApiGatewayTestSnapshot.cs | 2 +- .../SnapshotHelper}/SnapshotTestHelper.cs | 2 +- .../Snapshots/BinaryContentHttpV1.json | 0 .../Snapshots/BinaryContentRest.json | 0 ...odeAsFloat_ReturnsInternalServerError.json | 0 ...ValidResponse_MatchesDirectConversion.json | 0 ...nvalidJson_ReturnsErrorResponseHttpV1.json | 0 ..._InvalidJson_ReturnsErrorResponseRest.json | 0 ...esponse_MatchesDirectConversionHttpV1.json | 0 ...ConversionInvalid_JSON_Partial_Object.json | 0 ...nse_MatchesDirectConversionJSON_Array.json | 0 ...dResponse_MatchesDirectConversionRest.json | 0 ...chesDirectConversionValid_JSON_Object.json | 0 ...sponse_MatchesDirectConversionboolean.json | 0 ...e_MatchesDirectConversionempty_string.json | 0 ...e_MatchesDirectConversionjson_special.json | 0 ...esponse_MatchesDirectConversionnumber.json | 0 ...esponse_MatchesDirectConversionstring.json | 0 ..._MatchesDirectConversionstring_spaces.json | 0 ...tchesDirectConversionstring_unescaped.json | 0 .../Snapshots/V1_APIHeadersHttpV1.json | 0 .../Snapshots/V1_APIHeadersRest.json | 0 ...binesSingleAndMultiValueHeadersHttpV1.json | 0 ...ombinesSingleAndMultiValueHeadersRest.json | 0 ...V1_DefaultsToCorrectContentTYpeHttpV1.json | 0 .../V1_DefaultsToCorrectContentTYpeRest.json | 0 .../V1_HandlesHeadersCorrectlyHttpV1.json | 0 .../V1_HandlesHeadersCorrectlyRest.json | 0 .../V1_HandlesZeroStatusCodeHttpV1.json | 0 .../V1_HandlesZeroStatusCodeRest.json | 0 .../Snapshots/V1_SetsBodyNonBase64HttpV1.json | 0 .../Snapshots/V1_SetsBodyNonBase64Rest.json | 0 .../Snapshots/V1_SetsContentLengthHttpV1.json | 0 .../Snapshots/V1_SetsContentLengthRest.json | 0 .../V1_SetsCorrectStatusCodeHttpV1.json | 0 .../V1_SetsCorrectStatusCodeRest.json | 0 .../Snapshots/V1_SetsHeadersHttpV1.json | 0 .../Snapshots/V1_SetsHeadersRest.json | 0 .../V1_SetsMultiValueHeadersHttpV1.json | 0 .../V1_SetsMultiValueHeadersRest.json | 0 .../Snapshots/V1_SimpleGetRequestHttpV1.json | 0 .../Snapshots/V1_SimpleGetRequestRest.json | 0 .../V1_SimpleJsonResponseHttpV1.json | 0 .../Snapshots/V1_SimpleJsonResponseRest.json | 0 .../V1_SpecialCharactersInPathHttpV1.json | 0 .../V1_SpecialCharactersInPathRest.json | 0 .../V1_UnicodeCharactersInPathHttpV1.json | 0 .../V1_UnicodeCharactersInPathRest.json | 0 .../V1_UrlEncodedQueryStringHttpV1.json | 0 .../V1_UrlEncodedQueryStringRest.json | 0 .../V1_UsesProvidedContentTypeHttpV1.json | 0 .../V1_UsesProvidedContentTypeRest.json | 0 .../Snapshots/V2_BinaryContent.json | 0 .../V2_DefaultsToTextPlainContentType.json | 0 .../V2_DoesNotOverrideExplicitValues.json | 0 .../Snapshots/V2_HandlesHeadersCorrectly.json | 0 .../Snapshots/V2_HandlesZeroStatusCode.json | 0 .../Snapshots/V2_HttpAPIHeaders.json | 0 .../Snapshots/V2_SetsBodyBase64.json | 0 .../Snapshots/V2_SetsBodyNonBase64.json | 0 .../Snapshots/V2_SetsCorrectStatusCode.json | 0 .../Snapshots/V2_SetsHeaders.json | 0 .../Snapshots/V2_SimpleGetRequest.json | 0 .../Snapshots/V2_SimpleJsonResponse.json | 0 .../Snapshots/V2_SpecialCharactersInPath.json | 0 .../Snapshots/V2_UnicodeCharactersInPath.json | 0 .../Snapshots/V2_UrlEncodedQueryString.json | 0 78 files changed, 479 insertions(+), 1046 deletions(-) delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs delete mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests/Helpers => Amazon.Lambda.TestTool.UnitTests}/ApiGatewayTestHelper.cs (98%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.Tests.Common => Amazon.Lambda.TestTool.UnitTests/Extensions}/ApiGatewayResponseTestCases.cs (67%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.Tests.Common => Amazon.Lambda.TestTool.UnitTests/Extensions}/HttpContextTestCases.cs (99%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot => Amazon.Lambda.TestTool.UnitTests/SnapshotHelper}/ApiGatewayTestSnapshot.cs (97%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot => Amazon.Lambda.TestTool.UnitTests/SnapshotHelper}/SnapshotTestHelper.cs (95%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/BinaryContentHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/BinaryContentRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_APIHeadersHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_APIHeadersRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_HandlesHeadersCorrectlyRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_HandlesZeroStatusCodeRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsBodyNonBase64HttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsBodyNonBase64Rest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsContentLengthHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsContentLengthRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsCorrectStatusCodeRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsHeadersHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsHeadersRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsMultiValueHeadersHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SetsMultiValueHeadersRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SimpleGetRequestHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SimpleGetRequestRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SimpleJsonResponseHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SimpleJsonResponseRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SpecialCharactersInPathHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_SpecialCharactersInPathRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UnicodeCharactersInPathHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UnicodeCharactersInPathRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UrlEncodedQueryStringHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UrlEncodedQueryStringRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UsesProvidedContentTypeHttpV1.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V1_UsesProvidedContentTypeRest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_BinaryContent.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_DefaultsToTextPlainContentType.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_DoesNotOverrideExplicitValues.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_HandlesHeadersCorrectly.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_HandlesZeroStatusCode.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_HttpAPIHeaders.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SetsBodyBase64.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SetsBodyNonBase64.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SetsCorrectStatusCode.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SetsHeaders.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SimpleGetRequest.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SimpleJsonResponse.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_SpecialCharactersInPath.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_UnicodeCharactersInPath.json (100%) rename Tools/LambdaTestTool-v2/tests/{Amazon.Lambda.TestTool.IntegrationTests => Amazon.Lambda.TestTool.UnitTests}/Snapshots/V2_UrlEncodedQueryString.json (100%) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj index 9b7481c06..92b0900bf 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Amazon.Lambda.TestTool.IntegrationTests.csproj @@ -40,8 +40,4 @@ - - - - diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs deleted file mode 100644 index 714d4d37e..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsAdditionalTests.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Amazon.Lambda.APIGatewayEvents; -using Microsoft.AspNetCore.Http; -using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.Models; -using System.Text; -using Xunit; - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - public class ApiGatewayResponseExtensionsAdditionalTests - { - [Fact] - public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() - { - var testResponse = new APIGatewayProxyResponse - { - StatusCode = 200, - Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), - IsBase64Encoded = true - }; - - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.Rest); - - httpContext.Response.Body.Position = 0; - - Assert.Equal(200, (int)httpContext.Response.StatusCode); - var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); - Assert.Equal("test", content); - } - - [Fact] - public async Task ToHttpResponse_HttpV1APIGatewayV1DecodesBase64() - { - var testResponse = new APIGatewayProxyResponse - { - StatusCode = 200, - Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), - IsBase64Encoded = true - }; - - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.HttpV1); - - httpContext.Response.Body.Position = 0; - - Assert.Equal(200, (int)httpContext.Response.StatusCode); - var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); - Assert.Equal("test", content); - - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs deleted file mode 100644 index aed687175..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayResponseExtensionsTests.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Amazon.Lambda.APIGatewayEvents; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers; -using Amazon.Lambda.TestTool.Models; -using Amazon.Lambda.TestTool.Tests.Common; -using Xunit; -using static Amazon.Lambda.TestTool.Tests.Common.ApiGatewayResponseTestCases; - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - public class ApiGatewayResponseExtensionsTests - { - private ApiGatewayTestHelper _helper = new(); - - [Theory] - [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) - { - await RunV1Test(testCase, ApiGatewayEmulatorMode.Rest, testName); - } - - [Theory] - [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) - { - await RunV1Test(testCase, ApiGatewayEmulatorMode.HttpV1, testName); - } - - [Theory] - [MemberData(nameof(V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) - { - var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; - Assert.NotNull(testResponse); - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, testName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - await testCase.IntegrationAssertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); - } - - private async Task RunV1Test(ApiGatewayResponseTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) - { - var testResponse = testCase.Response as APIGatewayProxyResponse; - Assert.NotNull(testResponse); - var testCaseName = testName + emulatorMode; - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, emulatorMode, testCaseName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - await testCase.IntegrationAssertions(actualResponse, emulatorMode); - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs deleted file mode 100644 index 335e4e800..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/HttpContextExtensionsTests.cs +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using System.Net; -using Amazon.Lambda.APIGatewayEvents; -using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.Models; -using Amazon.Lambda.TestTool.Tests.Common; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Primitives; -using Xunit; -using static Amazon.Lambda.TestTool.Tests.Common.HttpContextTestCases; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; - -namespace Amazon.Lambda.TestTool.IntegrationTests -{ - public class HttpContextExtensionsTests - { - private readonly SnapshotTestHelper _snapshots; - - public HttpContextExtensionsTests() - { - _snapshots = new SnapshotTestHelper(); - } - - [Theory] - [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCase testCase) - { - var testCaseName = testName + ApiGatewayEmulatorMode.Rest; - return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, testCaseName); - } - - [Theory] - [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) - { - var testCaseName = testName + ApiGatewayEmulatorMode.HttpV1; - - return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, testCaseName); - } - - [Theory] - [MemberData(nameof(V2TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV2(string testName, HttpContextTestCase testCase) - { - return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV2, testName); - } - - [Fact] - public Task BinaryContentHttpV1() - { - var httpContext = CreateHttpContext("POST", "/test3/api/users/123/avatar", - new Dictionary { { "Content-Type", "application/octet-stream" } }, - body: new byte[] { 1, 2, 3, 4, 5 }); - - var config = new ApiGatewayRouteConfig - { - LambdaResourceName = "UploadAvatarFunction", - Endpoint = "/test3/api/users/{userId}/avatar", - HttpMethod = "POST", - Path = "/test3/api/users/{userId}/avatar" - }; - - var testCase = new HttpContextTestCase - { - HttpContext = httpContext, - ApiGatewayRouteConfig = config, - Assertions = (actualRequest, emulatorMode) => - { - var typedRequest = (APIGatewayProxyRequest)actualRequest; - Assert.True(typedRequest.IsBase64Encoded); - Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body); - Assert.Equal("123", typedRequest.PathParameters["userId"]); - Assert.Equal("/test3/api/users/{userId}/avatar", typedRequest.Resource); - Assert.Equal("POST", typedRequest.HttpMethod); - } - }; - - return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, nameof(BinaryContentHttpV1)); - } - - [Fact] - public Task BinaryContentRest() - { - var httpContext = CreateHttpContext("POST", "/test4/api/users/123/avatar", - new Dictionary { { "Content-Type", "application/octet-stream" } }, - body: new byte[] { 1, 2, 3, 4, 5 }); - - var config = new ApiGatewayRouteConfig - { - Path = "/test4/api/users/{userId}/avatar", - Endpoint = "/test4/api/users/{userId}/avatar", - HttpMethod = "POST", - LambdaResourceName = "ReturnFullEventLambdaFunction" - }; - - var testCase = new HttpContextTestCase - { - HttpContext = httpContext, - ApiGatewayRouteConfig = config, - Assertions = (actualRequest, emulatorMode) => - { - var typedRequest = (APIGatewayProxyRequest)actualRequest; - Assert.True(typedRequest.IsBase64Encoded); - Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body); - Assert.Equal("123", typedRequest.PathParameters["userId"]); - Assert.Equal("/test4/api/users/{userId}/avatar", typedRequest.Resource); - Assert.Equal("POST", typedRequest.HttpMethod); - } - }; - - return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, nameof(BinaryContentRest)); - } - - private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) where T : class - { - - Func> converter = emulatorMode switch - { - ApiGatewayEmulatorMode.Rest => - async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.Rest), - ApiGatewayEmulatorMode.HttpV1 => - async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.HttpV1), - ApiGatewayEmulatorMode.HttpV2 => - async (context, cfg) => (T)(object)await context.ToApiGatewayHttpV2Request(cfg), - _ => throw new ArgumentException($"Unsupported gateway type: {emulatorMode}") - }; - - await RunApiGatewayTestInternal( - testCase, - converter, - emulatorMode, - testName); - } - - private async Task RunApiGatewayTestInternal( - HttpContextTestCase testCase, - Func> toApiGatewayRequest, - ApiGatewayEmulatorMode emulatorMode, - string testName) - where T : class - { - T actualApiGatewayRequest; - actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); - var expectedApiGatewayRequest = await toApiGatewayRequest(testCase.HttpContext, testCase.ApiGatewayRouteConfig); - CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest); - testCase.Assertions(actualApiGatewayRequest!, emulatorMode); - } - - private void CompareApiGatewayRequests(T expected, T actual) where T : class? - { - if (expected is APIGatewayProxyRequest v1Expected && actual is APIGatewayProxyRequest v1Actual) - { - CompareApiGatewayV1Requests(v1Expected, v1Actual); - } - else if (expected is APIGatewayHttpApiV2ProxyRequest v2Expected && actual is APIGatewayHttpApiV2ProxyRequest v2Actual) - { - CompareApiGatewayV2Requests(v2Expected, v2Actual); - } - else - { - throw new ArgumentException("Unsupported type for comparison"); - } - } - - private void CompareApiGatewayV1Requests(APIGatewayProxyRequest expected, APIGatewayProxyRequest actual) - { - Assert.Equal(expected.HttpMethod, actual.HttpMethod); - Assert.Equal(expected.Path, actual.Path); - Assert.Equal(expected.Resource, actual.Resource); - Assert.Equal(expected.Body, actual.Body); - Assert.Equal(expected.IsBase64Encoded, actual.IsBase64Encoded); - - CompareHeaders(expected.Headers, actual.Headers); - CompareMultiValueHeaders(expected.MultiValueHeaders, actual.MultiValueHeaders); - CompareDictionaries(expected.QueryStringParameters, actual.QueryStringParameters); - CompareDictionaries(expected.PathParameters, actual.PathParameters); - CompareDictionaries(expected.StageVariables, actual.StageVariables); - CompareDictionaries(expected.MultiValueQueryStringParameters, actual.MultiValueQueryStringParameters); - } - - private void CompareApiGatewayV2Requests(APIGatewayHttpApiV2ProxyRequest expected, APIGatewayHttpApiV2ProxyRequest actual) - { - Assert.Equal(expected.RouteKey, actual.RouteKey); - Assert.Equal(expected.RawPath, actual.RawPath); - Assert.Equal(expected.RawQueryString, actual.RawQueryString); - Assert.Equal(expected.Body, actual.Body); - Assert.Equal(expected.IsBase64Encoded, actual.IsBase64Encoded); - Assert.Equal(expected.Version, actual.Version); - - CompareHeaders(expected.Headers, actual.Headers); - CompareDictionaries(expected.QueryStringParameters, actual.QueryStringParameters); - CompareDictionaries(expected.PathParameters, actual.PathParameters); - CompareStringArrays(expected.Cookies, actual.Cookies); - - CompareRequestContexts(expected.RequestContext, actual.RequestContext); - } - - private void CompareHeaders(IDictionary expected, IDictionary actual) - { - var expectedFiltered = FilterHeaders(expected); - var actualFiltered = FilterHeaders(actual); - - Assert.Equal(expectedFiltered.Count, actualFiltered.Count); - - foreach (var kvp in expectedFiltered) - { - Assert.True(actualFiltered.Keys.Any(k => string.Equals(k, kvp.Key, StringComparison.OrdinalIgnoreCase)), - $"Actual headers do not contain key: {kvp.Key}"); - - var actualValue = actualFiltered.First(pair => string.Equals(pair.Key, kvp.Key, StringComparison.OrdinalIgnoreCase)).Value; - Assert.Equal(kvp.Value, actualValue); - } - } - - private void CompareMultiValueHeaders(IDictionary> expected, IDictionary> actual) - { - var expectedFiltered = FilterHeaders(expected); - var actualFiltered = FilterHeaders(actual); - - Assert.Equal(expectedFiltered.Count, actualFiltered.Count); - - foreach (var kvp in expectedFiltered) - { - Assert.True(actualFiltered.Keys.Any(k => string.Equals(k, kvp.Key, StringComparison.OrdinalIgnoreCase)), - $"Actual headers do not contain key: {kvp.Key}"); - - var actualValue = actualFiltered.First(pair => string.Equals(pair.Key, kvp.Key, StringComparison.OrdinalIgnoreCase)).Value; - Assert.Equal(kvp.Value, actualValue); - } - } - - private IDictionary FilterHeaders(IDictionary headers) where TKey : notnull - { - return headers.Where(kvp => - !(kvp.Key.ToString()!.StartsWith("x-forwarded-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString()!.StartsWith("cloudfront-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString()!.StartsWith("via-", StringComparison.OrdinalIgnoreCase) || // ignore these for now - kvp.Key.ToString()!.Equals("x-amzn-trace-id", StringComparison.OrdinalIgnoreCase) || // this is dynamic so ignoring for now - kvp.Key.ToString()!.Equals("cookie", StringComparison.OrdinalIgnoreCase) || // TODO may have to have api gateway v2 not set this in headers - kvp.Key.ToString()!.Equals("host", StringComparison.OrdinalIgnoreCase))) // TODO we may want to set this - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); - } - - private void CompareDictionaries(IDictionary? expected, IDictionary? actual) - { - if (expected == null && actual == null) return; - if (expected == null && actual != null) Assert.Fail(); - if (expected != null && actual == null) Assert.Fail(); - Assert.Equal(expected!.Count, actual!.Count); - - foreach (var kvp in expected) - { - Assert.True(actual.ContainsKey(kvp.Key), $"Actual does not contain key: {kvp.Key}"); - Assert.Equal(kvp.Value, actual[kvp.Key]); - } - } - - private void CompareStringArrays(string[] expected, string[] actual) - { - Assert.Equal(expected?.Length, actual?.Length); - if (expected != null) - { - Assert.Equal(expected.OrderBy(x => x), actual?.OrderBy(x => x)); - } - } - - private void CompareRequestContexts(APIGatewayHttpApiV2ProxyRequest.ProxyRequestContext expected, APIGatewayHttpApiV2ProxyRequest.ProxyRequestContext actual) - { - Assert.Equal(expected.RouteKey, actual.RouteKey); - - Assert.Equal(expected.Http.Method, actual.Http.Method); - Assert.Equal(expected.Http.Path, actual.Http.Path); - Assert.Equal(expected.Http.Protocol, actual.Http.Protocol); - Assert.Equal(expected.Http.UserAgent, actual.Http.UserAgent); - } - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs deleted file mode 100644 index 91fc86926..000000000 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/InvokeResponseExtensionsIntegrationTests.cs +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using Amazon.Lambda.APIGatewayEvents; -using Amazon.Lambda.Model; -using Amazon.Lambda.TestTool.Models; -using System.Text; -using System.Text.Json; -using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers; -using Xunit; - -namespace Amazon.Lambda.TestTool.IntegrationTests; - -/// -/// Integration tests for InvokeResponseExtensions. -/// -/// -/// Developer's Note: -/// These tests don't have direct access to the intermediate result of the Lambda to API Gateway conversion. -/// Instead, we test the final API Gateway response object to ensure our conversion methods produce results -/// that match the actual API Gateway behavior. This approach allows us to verify the correctness of our -/// conversion methods within the constraints of not having access to AWS's internal conversion process. -/// -public class InvokeResponseExtensionsIntegrationTests -{ - - private readonly ApiGatewayTestHelper _helper = new(); - - [Theory] - [InlineData(ApiGatewayEmulatorMode.Rest)] - [InlineData(ApiGatewayEmulatorMode.HttpV1)] - public async Task ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion(ApiGatewayEmulatorMode emulatorMode) - { - // Arrange - var testResponse = new APIGatewayProxyResponse - { - StatusCode = 200, - Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), - Headers = new Dictionary { { "Content-Type", "application/json" } } - }; - var invokeResponse = new InvokeResponse - { - Payload = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(testResponse))) - }; - - // Act - var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); - - var testName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + emulatorMode; - - // Assert - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - } - - [Fact] - public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion() - { - // Arrange - var testResponse = new APIGatewayHttpApiV2ProxyResponse - { - StatusCode = 200, - Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), - Headers = new Dictionary { { "Content-Type", "application/json" } } - }; - var invokeResponse = new InvokeResponse - { - Payload = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(testResponse))) - }; - - // Act - var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); - - // Assert - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - } - - [Theory] - [InlineData(ApiGatewayEmulatorMode.Rest, 502, "Internal server error")] - [InlineData(ApiGatewayEmulatorMode.HttpV1, 500, "Internal Server Error")] - public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(ApiGatewayEmulatorMode emulatorMode, int expectedStatusCode, string expectedErrorMessage) - { - // Arrange - var invokeResponse = new InvokeResponse - { - Payload = new MemoryStream(Encoding.UTF8.GetBytes("Not a valid proxy response object")) - }; - - // Act - var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); - - var testName = nameof(ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse) + emulatorMode; - - // Assert - Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); - Assert.Contains(expectedErrorMessage, convertedResponse.Body); - - var (actualResponse, _) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); - Assert.Equal(expectedStatusCode, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Contains(expectedErrorMessage, content); - } - - /// - /// Tests various Lambda return values to verify API Gateway's handling of responses. - /// - /// The payload returned by the Lambda function. - /// - /// This test demonstrates a discrepancy between the official AWS documentation - /// and the actual observed behavior of API Gateway HTTP API v2 with Lambda - /// proxy integrations (payload format version 2.0). - /// - /// Official documentation states: - /// "If your Lambda function returns valid JSON and doesn't return a statusCode, - /// API Gateway assumes a 200 status code and treats the entire response as the body." - /// - /// However, the observed behavior (which this test verifies) is: - /// - API Gateway does not validate whether the returned data is valid JSON. - /// - Any response from the Lambda function that is not a properly formatted - /// API Gateway response object (i.e., an object with a 'statusCode' property) - /// is treated as a raw body in a 200 OK response. - /// - This includes valid JSON objects without a statusCode, JSON arrays, - /// primitive values, and invalid JSON strings. - /// - /// This test ensures that our ToApiGatewayHttpApiV2ProxyResponse method - /// correctly replicates this observed behavior, rather than the documented behavior. - /// - [Theory] - [InlineData("Invalid_JSON_Partial_Object", "{\"name\": \"John Doe\", \"age\":", "{\"name\": \"John Doe\", \"age\":")] // Invalid JSON (partial object) - [InlineData("Valid_JSON_Object", "{\"name\": \"John Doe\", \"age\": 30}", "{\"name\": \"John Doe\", \"age\": 30}")] // Valid JSON object without statusCode - [InlineData("JSON_Array", "[1, 2, 3, 4, 5]", "[1, 2, 3, 4, 5]")] // JSON array - [InlineData("string", "Hello, World!", "Hello, World!")] // String primitive - [InlineData("number", "42", "42")] // Number primitive - [InlineData("boolean", "true", "true")] // Boolean primitive - [InlineData("string_unescaped", "\"test\"", "test")] // JSON string that should be unescaped - [InlineData("string_spaces", "\"Hello, World!\"", "Hello, World!")] // JSON string with spaces - [InlineData("empty_string", "\"\"", "")] // Empty JSON string - [InlineData("json_special", "\"Special \\\"quoted\\\" text\"", "Special \"quoted\" text")] // JSON string with escaped quotes - public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRawBody( - string testName, - string inputPayload, - string expectedResponsePayload) - { - // Arrange - var invokeResponse = new InvokeResponse - { - Payload = new MemoryStream(Encoding.UTF8.GetBytes(inputPayload)) - }; - - // Act - var actualConvertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); - - var testCaseName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + testName; - - // Assert - Assert.Equal(200, actualConvertedResponse.StatusCode); - Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); - Assert.Equal("application/json", actualConvertedResponse.Headers["Content-Type"]); - - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(actualConvertedResponse, testCaseName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - - // Additional checks for API Gateway specific behavior - Assert.Equal(200, (int)actualResponse.StatusCode); - var actualContent = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal(expectedResponsePayload, actualContent); - Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); - } - - [Fact] - public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError() - { - // Arrange - var responsePayload = "{\"statusCode\": 200.5, \"body\": \"Hello\", \"headers\": {\"Content-Type\": \"text/plain\"}}"; - var invokeResponse = new InvokeResponse - { - Payload = new MemoryStream(Encoding.UTF8.GetBytes(responsePayload)) - }; - - // Act - var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); - - // Assert - Assert.Equal(500, convertedResponse.StatusCode); - Assert.Equal("{\"message\":\"Internal Server Error\"}", convertedResponse.Body); - Assert.Equal("application/json", convertedResponse.Headers["Content-Type"]); - - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - - // Additional checks for API Gateway specific behavior - Assert.Equal(500, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Internal Server Error\"}", content); - Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); - } -} diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs similarity index 98% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs index 132f6eccf..0d22262f5 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/ApiGatewayTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs @@ -4,8 +4,8 @@ using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; using Amazon.Lambda.TestTool.Models; +using Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; using Microsoft.AspNetCore.Http; using Xunit; diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs index 7611995ba..0fa654023 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs @@ -4,64 +4,68 @@ using System.Text; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; -using Amazon.Lambda.TestTool.Tests.Common; using Microsoft.AspNetCore.Http; using Xunit; -using static Amazon.Lambda.TestTool.Tests.Common.ApiGatewayResponseTestCases; +using static Amazon.Lambda.TestTool.UnitTests.Extensions.ApiGatewayResponseTestCases; namespace Amazon.Lambda.TestTool.UnitTests.Extensions { - public class ApiGatewayResponseExtensionsUnitTests + public class ApiGatewayResponseExtensionsTests { + private ApiGatewayTestHelper _helper = new(); + [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToHttpResponse_ConvertsCorrectlyV1(string testName, ApiGatewayResponseTestCase testCase) + [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] + public async Task IntegrationTest_APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) { - // Arrange - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await ((APIGatewayProxyResponse)testCase.Response).ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.HttpV1); - - // Assert - testCase.Assertions(httpContext.Response, ApiGatewayEmulatorMode.HttpV1); + await RunV1Test(testCase, ApiGatewayEmulatorMode.Rest, testName); } [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToHttpResponse_ConvertsCorrectlyV1Rest(string testName, ApiGatewayResponseTestCase testCase) + [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] + public async Task IntegrationTest_APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) { - // Arrange - var httpContext = new DefaultHttpContext(); - httpContext.Response.Body = new MemoryStream(); - await ((APIGatewayProxyResponse)testCase.Response).ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.Rest); - - // Assert - testCase.Assertions(httpContext.Response, ApiGatewayEmulatorMode.Rest); + await RunV1Test(testCase, ApiGatewayEmulatorMode.HttpV1, testName); } [Theory] - [MemberData(nameof(ApiGatewayResponseTestCases.V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToHttpResponse_ConvertsCorrectlyV2(string testName, ApiGatewayResponseTestCase testCase) + [MemberData(nameof(V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] + public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) { - // Arrange + var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; + Assert.NotNull(testResponse); + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, testName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await testCase.Assertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); + } + + [Fact] + public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() + { + var testResponse = new APIGatewayProxyResponse + { + StatusCode = 200, + Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), + IsBase64Encoded = true + }; + var httpContext = new DefaultHttpContext(); httpContext.Response.Body = new MemoryStream(); - await ((APIGatewayHttpApiV2ProxyResponse)testCase.Response).ToHttpResponseAsync(httpContext); + await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.Rest); + + httpContext.Response.Body.Position = 0; - // Assert - testCase.Assertions(httpContext.Response, ApiGatewayEmulatorMode.HttpV2); + Assert.Equal(200, (int)httpContext.Response.StatusCode); + var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); + Assert.Equal("test", content); } - [Theory] - [InlineData(ApiGatewayEmulatorMode.HttpV1)] - [InlineData(ApiGatewayEmulatorMode.Rest)] - public async Task ToHttpResponse_APIGatewayV1DecodesBase64(ApiGatewayEmulatorMode emulatorMode) + [Fact] + public async Task ToHttpResponse_HttpV1APIGatewayV1DecodesBase64() { - var apiResponse = new APIGatewayProxyResponse + var testResponse = new APIGatewayProxyResponse { StatusCode = 200, Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), @@ -70,12 +74,23 @@ public async Task ToHttpResponse_APIGatewayV1DecodesBase64(ApiGatewayEmulatorMod var httpContext = new DefaultHttpContext(); httpContext.Response.Body = new MemoryStream(); - await apiResponse.ToHttpResponseAsync(httpContext, emulatorMode); + await testResponse.ToHttpResponseAsync(httpContext, ApiGatewayEmulatorMode.HttpV1); + + httpContext.Response.Body.Position = 0; - httpContext.Response.Body.Seek(0, SeekOrigin.Begin); - using var reader = new StreamReader(httpContext.Response.Body); - var bodyContent = await reader.ReadToEndAsync(); - Assert.Equal("test", bodyContent); + Assert.Equal(200, (int)httpContext.Response.StatusCode); + var content = await new StreamReader(httpContext.Response.Body).ReadToEndAsync(); + Assert.Equal("test", content); + } + + private async Task RunV1Test(ApiGatewayResponseTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) + { + var testResponse = testCase.Response as APIGatewayProxyResponse; + Assert.NotNull(testResponse); + var testCaseName = testName + emulatorMode; + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, emulatorMode, testCaseName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await testCase.Assertions(actualResponse, emulatorMode); } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/ApiGatewayResponseTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs similarity index 67% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/ApiGatewayResponseTestCases.cs rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs index b5b62ede8..361c7a5bc 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/ApiGatewayResponseTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs @@ -5,10 +5,9 @@ using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Models; -using Microsoft.AspNetCore.Http; using Xunit; -namespace Amazon.Lambda.TestTool.Tests.Common; +namespace Amazon.Lambda.TestTool.UnitTests.Extensions; public static class ApiGatewayResponseTestCases { @@ -26,13 +25,7 @@ public static IEnumerable V1TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = (response, emulatormode) => - { - Assert.Equal(200, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal(200, (int)response.StatusCode); Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); @@ -53,11 +46,7 @@ public static IEnumerable V1TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal(201, response.StatusCode); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal(201, (int)response.StatusCode); await Task.CompletedTask; @@ -80,12 +69,7 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); Assert.True(response.Headers.Contains("X-Custom-Header")); @@ -109,11 +93,7 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With MultiValueHeaders\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal(new[] { "Value1", "Value2" }, response.Headers["X-Multi-Header"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.True(response.Headers.Contains("X-Multi-Header")); var multiHeaderValues = response.Headers.GetValues("X-Multi-Header").ToList(); @@ -135,11 +115,7 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"Hello, World!\"}", IsBase64Encoded = false }, - Assertions = (response, emulatormode) => - { - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { var content = await response.Content.ReadAsStringAsync(); Assert.Equal("{\"message\":\"Hello, World!\"}", content); @@ -158,17 +134,7 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = (response, emulatorMode) => - { - if (emulatorMode == ApiGatewayEmulatorMode.HttpV1) - { - Assert.Equal("text/plain; charset=utf-8", response.ContentType); - } else - { - Assert.Equal("application/json", response.ContentType); - } - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { if (emulatorMode == ApiGatewayEmulatorMode.HttpV1) { @@ -204,14 +170,7 @@ public static IEnumerable V1TestCases() StatusCode = 200 }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("test,other", response.Headers["myheader"]); - Assert.Equal("secondvalue", response.Headers["anotherheader"]); - Assert.Equal(new[] { "headervalue", "headervalue2" }, response.Headers["headername"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); Assert.Equal("test,other", response.Headers.GetValues("myheader").First()); @@ -245,14 +204,7 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"With Combined Headers\"}", StatusCode = 200 }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("single-value", response.Headers["X-Custom-Header"]); - Assert.Equal(new[] { "multi-value1", "multi-value2" }, response.Headers["X-Multi-Header"]); - Assert.Equal(new[] { "multi-value1", "multi-value2", "single-value" }, response.Headers["Combined-Header"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); Assert.Equal("single-value", response.Headers.GetValues("X-Custom-Header").First()); @@ -279,11 +231,7 @@ public static IEnumerable V1TestCases() IsBase64Encoded = false, StatusCode = 200 }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("{\"message\":\"Hello, World!\"}".Length, response.ContentLength); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("{\"message\":\"Hello, World!\"}".Length, response.Content.Headers.ContentLength); await Task.CompletedTask; @@ -301,29 +249,7 @@ public static IEnumerable V1TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = (response, emulatorMode) => - { - string error; - int contentLength; - int statusCode; - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - error = " \"Internal server error\"}"; - contentLength = 36; - statusCode = 502; - } - else - { - error = "\"Internal Server Error\"}"; - contentLength = 35; - statusCode = 500; - } - Assert.Equal(statusCode, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); - Assert.Equal(contentLength, response.ContentLength); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { string error; int contentLength; @@ -365,11 +291,7 @@ public static IEnumerable V1TestCases() { "Content-Type", "application/json" } } }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.ContentType); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); await Task.CompletedTask; @@ -386,27 +308,7 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = (response, emulatorMode) => - { - Assert.True(response.Headers.ContainsKey("Date")); - - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - Assert.True(response.Headers.ContainsKey("x-amzn-RequestId")); - Assert.True(response.Headers.ContainsKey("x-amz-apigw-id")); - Assert.True(response.Headers.ContainsKey("X-Amzn-Trace-Id")); - - Assert.Matches(@"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", response.Headers["x-amzn-RequestId"]); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["x-amz-apigw-id"]); - Assert.Matches(@"^Root=1-[0-9a-f]{8}-[0-9a-f]{24};Parent=[0-9a-f]{16};Sampled=0;Lineage=1:[0-9a-f]{8}:0$", response.Headers["X-Amzn-Trace-Id"]); - } - else // HttpV1 or HttpV2 - { - Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); - } - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.True(response.Headers.Contains("Date")); @@ -447,13 +349,7 @@ public static IEnumerable V2TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(200, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal(200, (int)response.StatusCode); Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); @@ -473,11 +369,7 @@ public static IEnumerable V2TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(201, response.StatusCode); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal(201, (int)response.StatusCode); await Task.CompletedTask; @@ -495,20 +387,7 @@ public static IEnumerable V2TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = (response, emulatorMode) => - { - string error; - int contentLength; - int statusCode; - error = "\"Internal Server Error\"}"; - contentLength = 35; - statusCode = 500; - Assert.Equal(statusCode, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); - Assert.Equal(contentLength, response.ContentLength); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { string error; int contentLength; @@ -542,12 +421,7 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); Assert.True(response.Headers.Contains("X-Custom-Header")); @@ -568,11 +442,7 @@ public static IEnumerable V2TestCases() Body = "{\"message\":\"Hello, API Gateway v2!\"}", IsBase64Encoded = false }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { var content = await response.Content.ReadAsStringAsync(); Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", content); @@ -591,11 +461,7 @@ public static IEnumerable V2TestCases() Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"message\":\"Hello, API Gateway v2!\"}")), IsBase64Encoded = true }, - Assertions = (response, emulatormode) => - { - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { var content = await response.Content.ReadAsStringAsync(); Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", content); @@ -613,11 +479,7 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("text/plain; charset=utf-8", response.ContentType); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("text/plain; charset=utf-8", response.Content.Headers.ContentType?.ToString()); await Task.CompletedTask; @@ -641,13 +503,7 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("test,shouldhavesecondvalue", response.Headers["myheader"]); - Assert.Equal("secondvalue", response.Headers["anotherheader"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); Assert.Equal("test,shouldhavesecondvalue", response.Headers.GetValues("myheader").First()); @@ -671,13 +527,7 @@ public static IEnumerable V2TestCases() { "Content-Type", "application/xml" } } }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(201, response.StatusCode); - Assert.Equal("application/xml", response.ContentType); - Assert.Equal("{\"key\":\"value\"}", ReadResponseBody(response)); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.Equal(201, (int)response.StatusCode); Assert.Equal("application/xml", response.Content.Headers.ContentType?.ToString()); @@ -697,14 +547,7 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = (response, emulatorMode) => - { - Assert.True(response.Headers.ContainsKey("Date")); - Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); - - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); - }, - IntegrationAssertions = async (response, emulatorMode) => + Assertions = async (response, emulatorMode) => { Assert.True(response.Headers.Contains("Date")); Assert.True(response.Headers.Contains("Apigw-Requestid")); @@ -717,18 +560,10 @@ public static IEnumerable V2TestCases() } - private static string ReadResponseBody(HttpResponse response) - { - response.Body.Seek(0, SeekOrigin.Begin); - using var reader = new StreamReader(response.Body); - return reader.ReadToEnd(); - } - public class ApiGatewayResponseTestCase { public required object Response { get; set; } - public required Action Assertions { get; set; } - public required Func IntegrationAssertions { get; set; } + public required Func Assertions { get; set; } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs index 27e6cf896..2a8f1ffec 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs @@ -1,250 +1,280 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; using Amazon.Lambda.TestTool.Models; -using Amazon.Lambda.TestTool.Tests.Common; +using Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using Xunit; -using static Amazon.Lambda.TestTool.Tests.Common.HttpContextTestCases; +using static Amazon.Lambda.TestTool.UnitTests.Extensions.HttpContextTestCases; namespace Amazon.Lambda.TestTool.UnitTests.Extensions { public class HttpContextExtensionsTests { + private readonly SnapshotTestHelper _snapshots; + + public HttpContextExtensionsTests() + { + _snapshots = new SnapshotTestHelper(); + } + [Theory] - [MemberData(nameof(HttpContextTestCases.V1TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToApiGatewayRequestRest_ConvertsCorrectly(string testName, HttpContextTestCase testCase) + public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCase testCase) { - // Arrange - var context = testCase.HttpContext; - - // Act - var result = await context.ToApiGatewayRequest(testCase.ApiGatewayRouteConfig, ApiGatewayEmulatorMode.Rest); - - // Assert - testCase.Assertions(result, ApiGatewayEmulatorMode.Rest); + var testCaseName = testName + ApiGatewayEmulatorMode.Rest; + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, testCaseName); } [Theory] - [MemberData(nameof(HttpContextTestCases.V1TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToApiGatewayRequestV1_ConvertsCorrectly(string testName, HttpContextTestCase testCase) + public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) { - // Arrange - var context = testCase.HttpContext; - - // Act - var result = await context.ToApiGatewayRequest(testCase.ApiGatewayRouteConfig, ApiGatewayEmulatorMode.HttpV1); + var testCaseName = testName + ApiGatewayEmulatorMode.HttpV1; - // Assert - testCase.Assertions(result, ApiGatewayEmulatorMode.HttpV1); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, testCaseName); } [Theory] - [MemberData(nameof(HttpContextTestCases.V2TestCases), MemberType = typeof(HttpContextTestCases))] + [MemberData(nameof(V2TestCases), MemberType = typeof(HttpContextTestCases))] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public async Task ToApiGatewayHttpV2Request_ConvertsCorrectly(string testName, HttpContextTestCase testCase) + public Task IntegrationTest_APIGatewayV2(string testName, HttpContextTestCase testCase) { - // Arrange - var context = testCase.HttpContext; - - // Act - var result = await context.ToApiGatewayHttpV2Request(testCase.ApiGatewayRouteConfig); - - // Assert - testCase.Assertions(result, ApiGatewayEmulatorMode.HttpV2); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV2, testName); } [Fact] - public async Task ToApiGatewayHttpV2Request_EmptyCollections() + public Task BinaryContentHttpV1() { + var httpContext = CreateHttpContext("POST", "/test3/api/users/123/avatar", + new Dictionary { { "Content-Type", "application/octet-stream" } }, + body: new byte[] { 1, 2, 3, 4, 5 }); - var httpContext = CreateHttpContext("POST", "/test10/api/notmatchingpath/123/orders"); var config = new ApiGatewayRouteConfig { - LambdaResourceName = "TestLambdaFunction", - Endpoint = "/test10/api/users/{userId}/orders", + LambdaResourceName = "UploadAvatarFunction", + Endpoint = "/test3/api/users/{userId}/avatar", HttpMethod = "POST", - Path = "/test10/api/users/{userId}/orders" + Path = "/test3/api/users/{userId}/avatar" }; - // Act - var result = await httpContext.ToApiGatewayHttpV2Request(config); - Assert.Equal(2, result.Headers.Count); - Assert.Equal("0", result.Headers["content-length"]); - Assert.Equal("text/plain; charset=utf-8", result.Headers["content-type"]); - Assert.Null(result.QueryStringParameters); - Assert.Null(result.PathParameters); - Assert.Null(result.Cookies); + var testCase = new HttpContextTestCase + { + HttpContext = httpContext, + ApiGatewayRouteConfig = config, + Assertions = (actualRequest, emulatorMode) => + { + var typedRequest = (APIGatewayProxyRequest)actualRequest; + Assert.True(typedRequest.IsBase64Encoded); + Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body); + Assert.Equal("123", typedRequest.PathParameters["userId"]); + Assert.Equal("/test3/api/users/{userId}/avatar", typedRequest.Resource); + Assert.Equal("POST", typedRequest.HttpMethod); + } + }; + + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV1, nameof(BinaryContentHttpV1)); } [Fact] - public async Task ToApiGatewayHttpV1Request_EmptyCollections() + public Task BinaryContentRest() { - var httpContext = CreateHttpContext("POST", "/test10/api/notmatchingpath/123/orders"); + var httpContext = CreateHttpContext("POST", "/test4/api/users/123/avatar", + new Dictionary { { "Content-Type", "application/octet-stream" } }, + body: new byte[] { 1, 2, 3, 4, 5 }); + var config = new ApiGatewayRouteConfig { - LambdaResourceName = "TestLambdaFunction", - Endpoint = "/test10/api/users/{userId}/orders", + Path = "/test4/api/users/{userId}/avatar", + Endpoint = "/test4/api/users/{userId}/avatar", HttpMethod = "POST", - Path = "/test10/api/users/{userId}/orders" + LambdaResourceName = "ReturnFullEventLambdaFunction" + }; + + var testCase = new HttpContextTestCase + { + HttpContext = httpContext, + ApiGatewayRouteConfig = config, + Assertions = (actualRequest, emulatorMode) => + { + var typedRequest = (APIGatewayProxyRequest)actualRequest; + Assert.True(typedRequest.IsBase64Encoded); + Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), typedRequest.Body); + Assert.Equal("123", typedRequest.PathParameters["userId"]); + Assert.Equal("/test4/api/users/{userId}/avatar", typedRequest.Resource); + Assert.Equal("POST", typedRequest.HttpMethod); + } }; - // Act - var result = await httpContext.ToApiGatewayRequest(config, ApiGatewayEmulatorMode.HttpV1); - Assert.Equal(2, result.Headers.Count); - Assert.Equal("0", result.Headers["content-length"]); - Assert.Equal("text/plain; charset=utf-8", result.Headers["content-type"]); - Assert.Equal(new List { "0" }, result.MultiValueHeaders["content-length"]); - Assert.Equal(new List { "text/plain; charset=utf-8" }, result.MultiValueHeaders["content-type"]); - Assert.Null(result.QueryStringParameters); - Assert.Null(result.MultiValueQueryStringParameters); - Assert.Null(result.PathParameters); + return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, nameof(BinaryContentRest)); } - [Theory] - [InlineData(ApiGatewayEmulatorMode.Rest)] - [InlineData(ApiGatewayEmulatorMode.HttpV1)] - public async Task ToApiGateway_MultiValueHeader(ApiGatewayEmulatorMode emulatorMode) + private async Task RunApiGatewayTest(HttpContextTestCase testCase, ApiGatewayEmulatorMode emulatorMode, string testName) where T : class { - var httpContext = CreateHttpContext("POST", "/test1/api/users/123/orders", - new Dictionary - { - { "Accept", new StringValues(new[] { "text/html", "application/json" }) }, - }); - var config = new ApiGatewayRouteConfig + + Func> converter = emulatorMode switch { - LambdaResourceName = "TestLambdaFunction", - Endpoint = "/test1/api/users/{userId}/orders", - HttpMethod = "POST", - Path = "/test1/api/users/{userId}/orders" + ApiGatewayEmulatorMode.Rest => + async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.Rest), + ApiGatewayEmulatorMode.HttpV1 => + async (context, cfg) => (T)(object)await context.ToApiGatewayRequest(cfg, ApiGatewayEmulatorMode.HttpV1), + ApiGatewayEmulatorMode.HttpV2 => + async (context, cfg) => (T)(object)await context.ToApiGatewayHttpV2Request(cfg), + _ => throw new ArgumentException($"Unsupported gateway type: {emulatorMode}") }; - var result = await httpContext.ToApiGatewayRequest(config, emulatorMode); - Assert.Equal(["text/html", "application/json"], result.MultiValueHeaders["accept"]); + await RunApiGatewayTestInternal( + testCase, + converter, + emulatorMode, + testName); } + private async Task RunApiGatewayTestInternal( + HttpContextTestCase testCase, + Func> toApiGatewayRequest, + ApiGatewayEmulatorMode emulatorMode, + string testName) + where T : class + { + T actualApiGatewayRequest; + actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); + var expectedApiGatewayRequest = await toApiGatewayRequest(testCase.HttpContext, testCase.ApiGatewayRouteConfig); + CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest); + testCase.Assertions(actualApiGatewayRequest!, emulatorMode); + } - [Fact] - public async Task ToApiGatewayHttpV1_EncodedAndUnicodeHeader() - { - var httpContext = CreateHttpContext("POST", "/test1/api/users/123/orders", - new Dictionary - { - { "X-Encoded-Header", "value%20with%20spaces" }, - { "X-Unicode-Header", "☕ Coffee" }, - { "X-Mixed-Header", "Hello%2C%20World%21%20☕" }, - { "X-Raw-Unicode", "\u2615 Coffee" } - }); - var config = new ApiGatewayRouteConfig + private void CompareApiGatewayRequests(T expected, T actual) where T : class? + { + if (expected is APIGatewayProxyRequest v1Expected && actual is APIGatewayProxyRequest v1Actual) { - LambdaResourceName = "TestLambdaFunction", - Endpoint = "/test1/api/users/{userId}/orders", - HttpMethod = "POST", - Path = "/test1/api/users/{userId}/orders" - }; + CompareApiGatewayV1Requests(v1Expected, v1Actual); + } + else if (expected is APIGatewayHttpApiV2ProxyRequest v2Expected && actual is APIGatewayHttpApiV2ProxyRequest v2Actual) + { + CompareApiGatewayV2Requests(v2Expected, v2Actual); + } + else + { + throw new ArgumentException("Unsupported type for comparison"); + } + } + + private void CompareApiGatewayV1Requests(APIGatewayProxyRequest expected, APIGatewayProxyRequest actual) + { + Assert.Equal(expected.HttpMethod, actual.HttpMethod); + Assert.Equal(expected.Path, actual.Path); + Assert.Equal(expected.Resource, actual.Resource); + Assert.Equal(expected.Body, actual.Body); + Assert.Equal(expected.IsBase64Encoded, actual.IsBase64Encoded); - var result = await httpContext.ToApiGatewayRequest(config, ApiGatewayEmulatorMode.HttpV1); - Assert.Equal("value%20with%20spaces", result.Headers["X-Encoded-Header"]); - Assert.Equal("☕ Coffee", result.Headers["X-Unicode-Header"]); - Assert.Equal("Hello%2C%20World%21%20☕", result.Headers["X-Mixed-Header"]); - Assert.Equal("\u2615 Coffee", result.Headers["X-Raw-Unicode"]); - Assert.Equal(new List { "value%20with%20spaces" }, result.MultiValueHeaders["X-Encoded-Header"]); - Assert.Equal(new List { "☕ Coffee" }, result.MultiValueHeaders["X-Unicode-Header"]); - Assert.Equal(new List { "Hello%2C%20World%21%20☕" }, result.MultiValueHeaders["X-Mixed-Header"]); - Assert.Equal(new List { "\u2615 Coffee" }, result.MultiValueHeaders["X-Raw-Unicode"]); - } - - - // Keeping this commented out for now. We have a backlog item DOTNET-7862 for this - //[Fact] - //public void ToApiGatewayRest_EncodedAndUnicodeHeader() - //{ - // var httpContext = CreateHttpContext("POST", "/test1/api/users/123/orders", - // new Dictionary - // { - // { "X-Encoded-Header", "value%20with%20spaces" }, - // { "X-Unicode-Header", "☕ Coffee" }, - // { "X-Mixed-Header", "Hello%2C%20World%21%20☕" }, - // { "X-Raw-Unicode", "\u2615 Coffee" } - // }); - // var config = new ApiGatewayRouteConfig - // { - // LambdaResourceName = "TestLambdaFunction", - // Endpoint = "/test1/api/users/{userId}/orders", - // HttpMethod = "POST", - // Path = "/test1/api/users/{userId}/orders" - // }; - - // var result = httpContext.ToApiGatewayRequest(config, ApiGatewayEmulatorMode.Rest); - // Assert.Equal("value%20with%20spaces", result.Headers["X-Encoded-Header"]); - // Assert.Equal("¬リユ Coffee", result.Headers["X-Unicode-Header"]); - // Assert.Equal("Hello%2C%20World%21%20¬リユ", result.Headers["X-Mixed-Header"]); - // Assert.Equal("\u2615 Coffee", result.Headers["X-Raw-Unicode"]); - // Assert.Equal(new List { "value%20with%20spaces" }, result.MultiValueHeaders["X-Encoded-Header"]); - // Assert.Equal(new List { "¬リユ Coffee" }, result.MultiValueHeaders["X-Unicode-Header"]); // in reality this is what rest api thinks it is - // Assert.Equal(new List { "Hello%2C%20World%21%20☕" }, result.MultiValueHeaders["X-Mixed-Header"]); - // Assert.Equal(new List { "\u2615 Coffee" }, result.MultiValueHeaders["X-Raw-Unicode"]); - //} + CompareHeaders(expected.Headers, actual.Headers); + CompareMultiValueHeaders(expected.MultiValueHeaders, actual.MultiValueHeaders); + CompareDictionaries(expected.QueryStringParameters, actual.QueryStringParameters); + CompareDictionaries(expected.PathParameters, actual.PathParameters); + CompareDictionaries(expected.StageVariables, actual.StageVariables); + CompareDictionaries(expected.MultiValueQueryStringParameters, actual.MultiValueQueryStringParameters); + } - [Fact] - public async Task ToApiGateway_EncodedAndUnicodeHeaderV2() - { - var httpContext = CreateHttpContext("POST", "/test1/api/users/123/orders", - new Dictionary - { - { "X-Encoded-Header", "value%20with%20spaces" }, - { "X-Unicode-Header", "☕ Coffee" }, - { "X-Mixed-Header", "Hello%2C%20World%21%20☕" }, - { "X-Raw-Unicode", "\u2615 Coffee" } - }); - var config = new ApiGatewayRouteConfig + private void CompareApiGatewayV2Requests(APIGatewayHttpApiV2ProxyRequest expected, APIGatewayHttpApiV2ProxyRequest actual) + { + Assert.Equal(expected.RouteKey, actual.RouteKey); + Assert.Equal(expected.RawPath, actual.RawPath); + Assert.Equal(expected.RawQueryString, actual.RawQueryString); + Assert.Equal(expected.Body, actual.Body); + Assert.Equal(expected.IsBase64Encoded, actual.IsBase64Encoded); + Assert.Equal(expected.Version, actual.Version); + + CompareHeaders(expected.Headers, actual.Headers); + CompareDictionaries(expected.QueryStringParameters, actual.QueryStringParameters); + CompareDictionaries(expected.PathParameters, actual.PathParameters); + CompareStringArrays(expected.Cookies, actual.Cookies); + + CompareRequestContexts(expected.RequestContext, actual.RequestContext); + } + + private void CompareHeaders(IDictionary expected, IDictionary actual) + { + var expectedFiltered = FilterHeaders(expected); + var actualFiltered = FilterHeaders(actual); + + Assert.Equal(expectedFiltered.Count, actualFiltered.Count); + + foreach (var kvp in expectedFiltered) { - LambdaResourceName = "TestLambdaFunction", - Endpoint = "/test1/api/users/{userId}/orders", - HttpMethod = "POST", - Path = "/test1/api/users/{userId}/orders" - }; + Assert.True(actualFiltered.Keys.Any(k => string.Equals(k, kvp.Key, StringComparison.OrdinalIgnoreCase)), + $"Actual headers do not contain key: {kvp.Key}"); - var result = await httpContext.ToApiGatewayHttpV2Request(config); - Assert.Equal("value%20with%20spaces", result.Headers["x-encoded-header"]); - Assert.Equal("☕ Coffee", result.Headers["x-unicode-header"]); - Assert.Equal("Hello%2C%20World%21%20☕", result.Headers["x-mixed-header"]); - Assert.Equal("\u2615 Coffee", result.Headers["x-raw-unicode"]); + var actualValue = actualFiltered.First(pair => string.Equals(pair.Key, kvp.Key, StringComparison.OrdinalIgnoreCase)).Value; + Assert.Equal(kvp.Value, actualValue); + } } - [Theory] - [InlineData(ApiGatewayEmulatorMode.Rest)] - [InlineData(ApiGatewayEmulatorMode.HttpV1)] - public async Task BinaryContentHttpV1(ApiGatewayEmulatorMode emulatorMode) + private void CompareMultiValueHeaders(IDictionary> expected, IDictionary> actual) { - // Arrange - var httpContext = CreateHttpContext("POST", "/test3/api/users/123/avatar", - new Dictionary { { "Content-Type", "application/octet-stream" } }, - body: new byte[] { 1, 2, 3, 4, 5 }); + var expectedFiltered = FilterHeaders(expected); + var actualFiltered = FilterHeaders(actual); - var config = new ApiGatewayRouteConfig + Assert.Equal(expectedFiltered.Count, actualFiltered.Count); + + foreach (var kvp in expectedFiltered) { - LambdaResourceName = "UploadAvatarFunction", - Endpoint = "/test3/api/users/{userId}/avatar", - HttpMethod = "POST", - Path = "/test3/api/users/{userId}/avatar" - }; + Assert.True(actualFiltered.Keys.Any(k => string.Equals(k, kvp.Key, StringComparison.OrdinalIgnoreCase)), + $"Actual headers do not contain key: {kvp.Key}"); + + var actualValue = actualFiltered.First(pair => string.Equals(pair.Key, kvp.Key, StringComparison.OrdinalIgnoreCase)).Value; + Assert.Equal(kvp.Value, actualValue); + } + } - // Act - var result = await httpContext.ToApiGatewayRequest(config, emulatorMode); + private IDictionary FilterHeaders(IDictionary headers) where TKey : notnull + { + return headers.Where(kvp => + !(kvp.Key.ToString()!.StartsWith("x-forwarded-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.StartsWith("cloudfront-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.StartsWith("via-", StringComparison.OrdinalIgnoreCase) || // ignore these for now + kvp.Key.ToString()!.Equals("x-amzn-trace-id", StringComparison.OrdinalIgnoreCase) || // this is dynamic so ignoring for now + kvp.Key.ToString()!.Equals("cookie", StringComparison.OrdinalIgnoreCase) || // TODO may have to have api gateway v2 not set this in headers + kvp.Key.ToString()!.Equals("host", StringComparison.OrdinalIgnoreCase))) // TODO we may want to set this + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + } + + private void CompareDictionaries(IDictionary? expected, IDictionary? actual) + { + if (expected == null && actual == null) return; + if (expected == null && actual != null) Assert.Fail(); + if (expected != null && actual == null) Assert.Fail(); + Assert.Equal(expected!.Count, actual!.Count); + + foreach (var kvp in expected) + { + Assert.True(actual.ContainsKey(kvp.Key), $"Actual does not contain key: {kvp.Key}"); + Assert.Equal(kvp.Value, actual[kvp.Key]); + } + } + + private void CompareStringArrays(string[] expected, string[] actual) + { + Assert.Equal(expected?.Length, actual?.Length); + if (expected != null) + { + Assert.Equal(expected.OrderBy(x => x), actual?.OrderBy(x => x)); + } + } + + private void CompareRequestContexts(APIGatewayHttpApiV2ProxyRequest.ProxyRequestContext expected, APIGatewayHttpApiV2ProxyRequest.ProxyRequestContext actual) + { + Assert.Equal(expected.RouteKey, actual.RouteKey); - // Assert - Assert.True(result.IsBase64Encoded); - Assert.Equal(Convert.ToBase64String(new byte[] { 1, 2, 3, 4, 5 }), result.Body); - Assert.Equal("123", result.PathParameters["userId"]); - Assert.Equal("/test3/api/users/{userId}/avatar", result.Resource); - Assert.Equal("POST", result.HttpMethod); - Assert.Equal("application/octet-stream", result.Headers["Content-Type"]); + Assert.Equal(expected.Http.Method, actual.Http.Method); + Assert.Equal(expected.Http.Path, actual.Http.Path); + Assert.Equal(expected.Http.Protocol, actual.Http.Protocol); + Assert.Equal(expected.Http.UserAgent, actual.Http.UserAgent); } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextTestCases.cs similarity index 99% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextTestCases.cs index aeb5fdc14..06d74b7c3 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.Tests.Common/HttpContextTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextTestCases.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Primitives; using Xunit; -namespace Amazon.Lambda.TestTool.Tests.Common +namespace Amazon.Lambda.TestTool.UnitTests.Extensions { public static class HttpContextTestCases { diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs index cc5a3db46..ca4475512 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs @@ -2,15 +2,201 @@ // SPDX-License-Identifier: Apache-2.0 using System.Text; +using System.Text.Json; +using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.Model; using Amazon.Lambda.TestTool.Extensions; +using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; using Xunit; namespace Amazon.Lambda.TestTool.UnitTests.Extensions; +/// +/// Integration tests for InvokeResponseExtensions. +/// +/// +/// Developer's Note: +/// These tests don't have direct access to the intermediate result of the Lambda to API Gateway conversion. +/// Instead, we test the final API Gateway response object to ensure our conversion methods produce results +/// that match the actual API Gateway behavior. This approach allows us to verify the correctness of our +/// conversion methods within the constraints of not having access to AWS's internal conversion process. +/// public class InvokeResponseExtensionsTests { + + private readonly ApiGatewayTestHelper _helper = new(); + + [Theory] + [InlineData(ApiGatewayEmulatorMode.Rest)] + [InlineData(ApiGatewayEmulatorMode.HttpV1)] + public async Task ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion(ApiGatewayEmulatorMode emulatorMode) + { + // Arrange + var testResponse = new APIGatewayProxyResponse + { + StatusCode = 200, + Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), + Headers = new Dictionary { { "Content-Type", "application/json" } } + }; + var invokeResponse = new InvokeResponse + { + Payload = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(testResponse))) + }; + + // Act + var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + + var testName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + emulatorMode; + + // Assert + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + } + + [Fact] + public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion() + { + // Arrange + var testResponse = new APIGatewayHttpApiV2ProxyResponse + { + StatusCode = 200, + Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), + Headers = new Dictionary { { "Content-Type", "application/json" } } + }; + var invokeResponse = new InvokeResponse + { + Payload = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(testResponse))) + }; + + // Act + var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + + // Assert + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + } + + [Theory] + [InlineData(ApiGatewayEmulatorMode.Rest, 502, "Internal server error")] + [InlineData(ApiGatewayEmulatorMode.HttpV1, 500, "Internal Server Error")] + public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(ApiGatewayEmulatorMode emulatorMode, int expectedStatusCode, string expectedErrorMessage) + { + // Arrange + var invokeResponse = new InvokeResponse + { + Payload = new MemoryStream(Encoding.UTF8.GetBytes("Not a valid proxy response object")) + }; + + // Act + var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + + var testName = nameof(ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse) + emulatorMode; + + // Assert + Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); + Assert.Contains(expectedErrorMessage, convertedResponse.Body); + + var (actualResponse, _) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); + Assert.Equal(expectedStatusCode, (int)actualResponse.StatusCode); + var content = await actualResponse.Content.ReadAsStringAsync(); + Assert.Contains(expectedErrorMessage, content); + } + + /// + /// Tests various Lambda return values to verify API Gateway's handling of responses. + /// + /// The payload returned by the Lambda function. + /// + /// This test demonstrates a discrepancy between the official AWS documentation + /// and the actual observed behavior of API Gateway HTTP API v2 with Lambda + /// proxy integrations (payload format version 2.0). + /// + /// Official documentation states: + /// "If your Lambda function returns valid JSON and doesn't return a statusCode, + /// API Gateway assumes a 200 status code and treats the entire response as the body." + /// + /// However, the observed behavior (which this test verifies) is: + /// - API Gateway does not validate whether the returned data is valid JSON. + /// - Any response from the Lambda function that is not a properly formatted + /// API Gateway response object (i.e., an object with a 'statusCode' property) + /// is treated as a raw body in a 200 OK response. + /// - This includes valid JSON objects without a statusCode, JSON arrays, + /// primitive values, and invalid JSON strings. + /// + /// This test ensures that our ToApiGatewayHttpApiV2ProxyResponse method + /// correctly replicates this observed behavior, rather than the documented behavior. + /// + [Theory] + [InlineData("Invalid_JSON_Partial_Object", "{\"name\": \"John Doe\", \"age\":", "{\"name\": \"John Doe\", \"age\":")] // Invalid JSON (partial object) + [InlineData("Valid_JSON_Object", "{\"name\": \"John Doe\", \"age\": 30}", "{\"name\": \"John Doe\", \"age\": 30}")] // Valid JSON object without statusCode + [InlineData("JSON_Array", "[1, 2, 3, 4, 5]", "[1, 2, 3, 4, 5]")] // JSON array + [InlineData("string", "Hello, World!", "Hello, World!")] // String primitive + [InlineData("number", "42", "42")] // Number primitive + [InlineData("boolean", "true", "true")] // Boolean primitive + [InlineData("string_unescaped", "\"test\"", "test")] // JSON string that should be unescaped + [InlineData("string_spaces", "\"Hello, World!\"", "Hello, World!")] // JSON string with spaces + [InlineData("empty_string", "\"\"", "")] // Empty JSON string + [InlineData("json_special", "\"Special \\\"quoted\\\" text\"", "Special \"quoted\" text")] // JSON string with escaped quotes + public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRawBody( + string testName, + string inputPayload, + string expectedResponsePayload) + { + // Arrange + var invokeResponse = new InvokeResponse + { + Payload = new MemoryStream(Encoding.UTF8.GetBytes(inputPayload)) + }; + + // Act + var actualConvertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + + var testCaseName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + testName; + + // Assert + Assert.Equal(200, actualConvertedResponse.StatusCode); + Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); + Assert.Equal("application/json", actualConvertedResponse.Headers["Content-Type"]); + + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(actualConvertedResponse, testCaseName); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + + // Additional checks for API Gateway specific behavior + Assert.Equal(200, (int)actualResponse.StatusCode); + var actualContent = await actualResponse.Content.ReadAsStringAsync(); + Assert.Equal(expectedResponsePayload, actualContent); + Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); + } + + [Fact] + public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError() + { + // Arrange + var responsePayload = "{\"statusCode\": 200.5, \"body\": \"Hello\", \"headers\": {\"Content-Type\": \"text/plain\"}}"; + var invokeResponse = new InvokeResponse + { + Payload = new MemoryStream(Encoding.UTF8.GetBytes(responsePayload)) + }; + + // Act + var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + + // Assert + Assert.Equal(500, convertedResponse.StatusCode); + Assert.Equal("{\"message\":\"Internal Server Error\"}", convertedResponse.Body); + Assert.Equal("application/json", convertedResponse.Headers["Content-Type"]); + + var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); + await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + + // Additional checks for API Gateway specific behavior + Assert.Equal(500, (int)actualResponse.StatusCode); + var content = await actualResponse.Content.ReadAsStringAsync(); + Assert.Equal("{\"message\":\"Internal Server Error\"}", content); + Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); + } + [Theory] [InlineData("{\"statusCode\": 200, \"body\": \"Hello\", \"headers\": {\"Content-Type\": \"text/plain\"}}", ApiGatewayEmulatorMode.Rest, 200, "Hello", "text/plain")] [InlineData("{\"statusCode\": 201, \"body\": \"Created\", \"headers\": {\"Content-Type\": \"application/json\"}}", ApiGatewayEmulatorMode.HttpV1, 201, "Created", "application/json")] @@ -38,27 +224,6 @@ public void ToApiGatewayProxyResponse_InvalidOrEmptyJson_ReturnsErrorResponse(st Assert.Equal("application/json", result.Headers["Content-Type"]); } - [Theory] - [InlineData("{\"statusCode\": 200, \"body\": \"Hello\", \"headers\": {\"Content-Type\": \"text/plain\"}}", 200, "Hello", "text/plain")] - [InlineData("{\"statusCode\": \"invalid\", \"body\": \"Hello\"}", 500, "{\"message\":\"Internal Server Error\"}", "application/json")] - [InlineData("{\"message\": \"Hello, World!\"}", 200, "{\"message\": \"Hello, World!\"}", "application/json")] - [InlineData("test", 200, "test", "application/json")] - [InlineData("\"test\"", 200, "test", "application/json")] - [InlineData("42", 200, "42", "application/json")] - [InlineData("true", 200, "true", "application/json")] - [InlineData("[1,2,3]", 200, "[1,2,3]", "application/json")] - [InlineData("{invalid json}", 200, "{invalid json}", "application/json")] - [InlineData("", 200, "", "application/json")] - public void ToApiGatewayHttpApiV2ProxyResponse_VariousInputs_ReturnsExpectedResult(string payload, int expectedStatusCode, string expectedBody, string expectedContentType) - { - var invokeResponse = CreateInvokeResponse(payload); - var result = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); - - Assert.Equal(expectedStatusCode, result.StatusCode); - Assert.Equal(expectedBody, result.Body); - Assert.Equal(expectedContentType, result.Headers["Content-Type"]); - } - [Fact] public void ToApiGatewayProxyResponse_UnsupportedEmulatorMode_ThrowsNotSupportedException() { @@ -68,23 +233,6 @@ public void ToApiGatewayProxyResponse_UnsupportedEmulatorMode_ThrowsNotSupported invokeResponse.ToApiGatewayProxyResponse(ApiGatewayEmulatorMode.HttpV2)); } - [Fact] - public void ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError() - { - // Arrange - var payload = "{\"statusCode\": 200.5, \"body\": \"Hello\", \"headers\": {\"Content-Type\": \"text/plain\"}}"; - var invokeResponse = CreateInvokeResponse(payload); - - // Act - var result = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); - - // Assert - Assert.Equal(500, result.StatusCode); - Assert.Equal("{\"message\":\"Internal Server Error\"}", result.Body); - Assert.Equal("application/json", result.Headers["Content-Type"]); - } - - private InvokeResponse CreateInvokeResponse(string payload) { return new InvokeResponse diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs similarity index 97% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs index 695fa920a..7b23fb5ec 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/ApiGatewayTestSnapshot.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs @@ -2,7 +2,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; +namespace Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; public class HttpResponseMessageConverter : JsonConverter { diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs similarity index 95% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs index a82a20fa6..00e7648b9 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Helpers/snapshot/SnapshotTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs @@ -3,7 +3,7 @@ using System.Text.Json; -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers.snapshot; +namespace Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; public class SnapshotTestHelper { private readonly string _snapshotDirectory; diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/BinaryContentRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_APIHeadersRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_HandlesZeroStatusCodeRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsBodyNonBase64Rest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsContentLengthRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsCorrectStatusCodeRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsHeadersRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SetsMultiValueHeadersRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleGetRequestRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SimpleJsonResponseRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_SpecialCharactersInPathRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UnicodeCharactersInPathRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UrlEncodedQueryStringRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V1_UsesProvidedContentTypeRest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_BinaryContent.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DefaultsToTextPlainContentType.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_DoesNotOverrideExplicitValues.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesHeadersCorrectly.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HandlesZeroStatusCode.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_HttpAPIHeaders.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyBase64.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsBodyNonBase64.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsCorrectStatusCode.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SetsHeaders.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleGetRequest.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SimpleJsonResponse.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_SpecialCharactersInPath.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UnicodeCharactersInPath.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json similarity index 100% rename from Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/Snapshots/V2_UrlEncodedQueryString.json rename to Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json From ad961afd3ffe451a500873d747cab2ab51c34b3b Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 20:25:10 -0400 Subject: [PATCH 4/9] refactor helper class --- .../ApiGatewayTestHelper.cs | 119 ++++---- .../ApiGatewayResponseExtensionsTests.cs | 22 +- .../Extensions/ApiGatewayResponseTestCases.cs | 253 ++++++++---------- .../Extensions/HttpContextExtensionsTests.cs | 8 +- .../InvokeResponseExtensionsTests.cs | 65 +++-- 5 files changed, 236 insertions(+), 231 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs index 0d22262f5..34845560e 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs @@ -9,63 +9,82 @@ using Microsoft.AspNetCore.Http; using Xunit; -namespace Amazon.Lambda.TestTool.IntegrationTests.Helpers +namespace Amazon.Lambda.TestTool.UnitTests { public class ApiGatewayTestHelper { - private readonly SnapshotTestHelper _snapshots; + private readonly SnapshotTestHelper _snapshots = new(new JsonSerializerOptions + { + WriteIndented = true, + Converters = { new HttpResponseMessageConverter() } + } + ); - public ApiGatewayTestHelper() + public async Task VerifyApiGatewayResponseAsync( + APIGatewayProxyResponse response, + ApiGatewayEmulatorMode emulatorMode, + string snapshotName, + Action? additionalAssertions = null) { - _snapshots = new SnapshotTestHelper(new JsonSerializerOptions - { - WriteIndented = true, - Converters = { new HttpResponseMessageConverter() } - } - ); + // Convert response to HttpResponse (simulates what API Gateway would do) + var convertedResponse = await ConvertToHttpResponseAsync(response, emulatorMode); + + // Load the expected response from snapshot + var expectedResponse = await _snapshots.LoadSnapshot(snapshotName); + + // Compare the responses + await AssertResponsesEqual(expectedResponse, convertedResponse); + + // Run any additional assertions + additionalAssertions?.Invoke(convertedResponse); } - public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( - APIGatewayProxyResponse testResponse, - ApiGatewayEmulatorMode emulatorMode, - string testName) + public async Task VerifyHttpApiV2ResponseAsync( + APIGatewayHttpApiV2ProxyResponse response, + string snapshotName, + Action? additionalAssertions = null) { - // Generate the expected response using ToHttpResponseAsync - var testResponseHttpContext = new DefaultHttpContext(); - testResponseHttpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(testResponseHttpContext, emulatorMode); + // Convert response to HttpResponse (simulates what API Gateway would do) + var convertedResponse = await ConvertToHttpResponseAsync(response); - HttpResponseMessage actualResponse; - actualResponse = await _snapshots.LoadSnapshot(testName); + // Load the expected response from snapshot + var expectedResponse = await _snapshots.LoadSnapshot(snapshotName); - return (actualResponse, testResponseHttpContext.Response); + // Compare the responses + await AssertResponsesEqual(expectedResponse, convertedResponse); + // Run any additional assertions + additionalAssertions?.Invoke(convertedResponse); } - public async Task<(HttpResponseMessage actualResponse, HttpResponse httpTestResponse)> ExecuteTestRequest( - APIGatewayHttpApiV2ProxyResponse testResponse, - string testName) + private async Task ConvertToHttpResponseAsync( + APIGatewayProxyResponse response, + ApiGatewayEmulatorMode emulatorMode) { - // Generate the expected response using ToHttpResponseAsync - var testResponseHttpContext = new DefaultHttpContext(); - testResponseHttpContext.Response.Body = new MemoryStream(); - await testResponse.ToHttpResponseAsync(testResponseHttpContext); - - HttpResponseMessage actualResponse; - actualResponse = await _snapshots.LoadSnapshot(testName); + var context = new DefaultHttpContext(); + context.Response.Body = new MemoryStream(); + await response.ToHttpResponseAsync(context, emulatorMode); + return context.Response; + } - return (actualResponse, testResponseHttpContext.Response); + private async Task ConvertToHttpResponseAsync( + APIGatewayHttpApiV2ProxyResponse response) + { + var context = new DefaultHttpContext(); + context.Response.Body = new MemoryStream(); + await response.ToHttpResponseAsync(context); + return context.Response; } - public async Task AssertResponsesEqual(HttpResponseMessage actualResponse, HttpResponse httpTestResponse) + private async Task AssertResponsesEqual(HttpResponseMessage expected, HttpResponse actual) { - httpTestResponse.Body.Seek(0, SeekOrigin.Begin); - var expectedContent = await new StreamReader(httpTestResponse.Body).ReadToEndAsync(); - var actualContent = await actualResponse.Content.ReadAsStringAsync(); + actual.Body.Seek(0, SeekOrigin.Begin); + var actualContent = await new StreamReader(actual.Body).ReadToEndAsync(); + var expectedContent = await expected.Content.ReadAsStringAsync(); - Assert.Equal(expectedContent, actualContent); + Assert.Equal(actualContent, expectedContent); - Assert.Equal(httpTestResponse.StatusCode, (int)actualResponse.StatusCode); + Assert.Equal(actual.StatusCode, (int)expected.StatusCode); // ignore these because they will vary in the real world. we will check manually in other test cases that these are set var headersToIgnore = new HashSet(StringComparer.OrdinalIgnoreCase) @@ -81,28 +100,28 @@ public async Task AssertResponsesEqual(HttpResponseMessage actualResponse, HttpR "X-Amz-Cf-Id" }; - foreach (var header in httpTestResponse.Headers) + foreach (var header in actual.Headers) { if (headersToIgnore.Contains(header.Key)) continue; - Assert.True(actualResponse.Headers.TryGetValues(header.Key, out var actualValues) || - actualResponse.Content.Headers.TryGetValues(header.Key, out actualValues), - $"Header '{header.Key}={string.Join(", ", header.Value.ToArray())}' not found in actual response"); + Assert.True(expected.Headers.TryGetValues(header.Key, out var expectedValues) || + expected.Content.Headers.TryGetValues(header.Key, out expectedValues), + $"Header '{header.Key}={string.Join(", ", header.Value.ToArray())}' not found in expected response"); - var sortedExpectedValues = header.Value.OrderBy(v => v).ToArray(); - var sortedActualValues = actualValues.OrderBy(v => v).ToArray(); - Assert.Equal(sortedExpectedValues, sortedActualValues); + var sortedActualValues = header.Value.OrderBy(v => v).ToArray(); + var sortedExpectedValues = expectedValues.OrderBy(v => v).ToArray(); + Assert.Equal(sortedActualValues, sortedExpectedValues); } - foreach (var header in actualResponse.Headers.Concat(actualResponse.Content.Headers)) + foreach (var header in expected.Headers.Concat(expected.Content.Headers)) { if (headersToIgnore.Contains(header.Key)) continue; - Assert.True(httpTestResponse.Headers.ContainsKey(header.Key), - $"Header '{header.Key}={string.Join(", ", header.Value)}' not found in test response"); + Assert.True(actual.Headers.ContainsKey(header.Key), + $"Header '{header.Key}={string.Join(", ", header.Value)}' not found in actual response"); - var sortedExpectedValues = httpTestResponse.Headers[header.Key].OrderBy(v => v).ToArray(); - var sortedActualValues = header.Value.OrderBy(v => v).ToArray(); - Assert.Equal(sortedExpectedValues, sortedActualValues); + var sortedActualValues = actual.Headers[header.Key].OrderBy(v => v).ToArray(); + var sortedExpectedValues = header.Value.OrderBy(v => v).ToArray(); + Assert.Equal(sortedActualValues, sortedExpectedValues); } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs index 0fa654023..d08221d03 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs @@ -4,7 +4,6 @@ using System.Text; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; using Microsoft.AspNetCore.Http; using Xunit; @@ -36,9 +35,11 @@ public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayRespon { var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; Assert.NotNull(testResponse); - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, testName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - await testCase.Assertions(actualResponse, ApiGatewayEmulatorMode.HttpV2); + await _helper.VerifyHttpApiV2ResponseAsync(testResponse, testName, + response => + { + testCase.Assertions(response, ApiGatewayEmulatorMode.HttpV2); + }); } [Fact] @@ -47,7 +48,7 @@ public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64() var testResponse = new APIGatewayProxyResponse { StatusCode = 200, - Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), + Body = Convert.ToBase64String("test"u8.ToArray()), IsBase64Encoded = true }; @@ -68,7 +69,7 @@ public async Task ToHttpResponse_HttpV1APIGatewayV1DecodesBase64() var testResponse = new APIGatewayProxyResponse { StatusCode = 200, - Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")), + Body = Convert.ToBase64String("test"u8.ToArray()), IsBase64Encoded = true }; @@ -88,9 +89,12 @@ private async Task RunV1Test(ApiGatewayResponseTestCase testCase, ApiGatewayEmul var testResponse = testCase.Response as APIGatewayProxyResponse; Assert.NotNull(testResponse); var testCaseName = testName + emulatorMode; - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(testResponse, emulatorMode, testCaseName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); - await testCase.Assertions(actualResponse, emulatorMode); + await _helper.VerifyApiGatewayResponseAsync(testResponse, emulatorMode, testCaseName, + httpResponse => + { + testCase.Assertions(httpResponse, emulatorMode); + }); + } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs index 361c7a5bc..082990420 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs @@ -5,6 +5,7 @@ using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.TestTool.Models; +using Microsoft.AspNetCore.Http; using Xunit; namespace Amazon.Lambda.TestTool.UnitTests.Extensions; @@ -25,14 +26,12 @@ public static IEnumerable V1TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.Equal(200, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Hello, World!\"}", content); - await Task.CompletedTask; - } + Assert.Equal(200, response.StatusCode); + Assert.Equal("application/json", response.ContentType); + Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); + }, } }; @@ -46,11 +45,10 @@ public static IEnumerable V1TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.Equal(201, (int)response.StatusCode); - await Task.CompletedTask; - } + Assert.Equal(201, response.StatusCode); + }, } }; @@ -69,13 +67,11 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - Assert.True(response.Headers.Contains("X-Custom-Header")); - Assert.Equal("CustomValue", response.Headers.GetValues("X-Custom-Header").First()); - await Task.CompletedTask; - } + Assert.Equal("application/json", response.Headers["Content-Type"]); + Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); + }, } }; @@ -93,14 +89,10 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With MultiValueHeaders\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.True(response.Headers.Contains("X-Multi-Header")); - var multiHeaderValues = response.Headers.GetValues("X-Multi-Header").ToList(); - Assert.Contains("Value1", multiHeaderValues); - Assert.Contains("Value2", multiHeaderValues); - await Task.CompletedTask; - } + Assert.Equal(new[] { "Value1", "Value2" }, response.Headers["X-Multi-Header"]); + }, } }; @@ -115,12 +107,10 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"Hello, World!\"}", IsBase64Encoded = false }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Hello, World!\"}", content); - await Task.CompletedTask; - } + Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); + }, } }; @@ -134,18 +124,16 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { if (emulatorMode == ApiGatewayEmulatorMode.HttpV1) { - Assert.Equal("text/plain; charset=utf-8", response.Content.Headers.ContentType?.ToString()); - } - else + Assert.Equal("text/plain; charset=utf-8", response.ContentType); + } else { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); + Assert.Equal("application/json", response.ContentType); } - await Task.CompletedTask; - } + }, } }; @@ -170,16 +158,13 @@ public static IEnumerable V1TestCases() StatusCode = 200 }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - Assert.Equal("test,other", response.Headers.GetValues("myheader").First()); - Assert.Equal("secondvalue", response.Headers.GetValues("anotherheader").First()); - var headernameValues = response.Headers.GetValues("headername").ToList(); - Assert.Contains("headervalue", headernameValues); - Assert.Contains("headervalue2", headernameValues); - await Task.CompletedTask; - } + Assert.Equal("application/json", response.Headers["Content-Type"]); + Assert.Equal("test,other", response.Headers["myheader"]); + Assert.Equal("secondvalue", response.Headers["anotherheader"]); + Assert.Equal(new[] { "headervalue", "headervalue2" }, response.Headers["headername"]); + }, } }; @@ -204,19 +189,13 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"With Combined Headers\"}", StatusCode = 200 }, - Assertions = async (response, emulatorMode) => - { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - Assert.Equal("single-value", response.Headers.GetValues("X-Custom-Header").First()); - var multiHeaderValues = response.Headers.GetValues("X-Multi-Header").ToList(); - Assert.Contains("multi-value1", multiHeaderValues); - Assert.Contains("multi-value2", multiHeaderValues); - var combinedHeaderValues = response.Headers.GetValues("Combined-Header").ToList(); - Assert.Contains("multi-value1", combinedHeaderValues); - Assert.Contains("multi-value2", combinedHeaderValues); - Assert.Contains("single-value", combinedHeaderValues); - await Task.CompletedTask; - } + Assertions = (response, emulatormode) => + { + Assert.Equal("application/json", response.Headers["Content-Type"]); + Assert.Equal("single-value", response.Headers["X-Custom-Header"]); + Assert.Equal(new[] { "multi-value1", "multi-value2" }, response.Headers["X-Multi-Header"]); + Assert.Equal(new[] { "multi-value1", "multi-value2", "single-value" }, response.Headers["Combined-Header"]); + }, } }; @@ -231,11 +210,10 @@ public static IEnumerable V1TestCases() IsBase64Encoded = false, StatusCode = 200 }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal("{\"message\":\"Hello, World!\"}".Length, response.Content.Headers.ContentLength); - await Task.CompletedTask; - } + Assert.Equal("{\"message\":\"Hello, World!\"}".Length, response.ContentLength); + }, } }; @@ -249,12 +227,11 @@ public static IEnumerable V1TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { string error; int contentLength; int statusCode; - if (emulatorMode == ApiGatewayEmulatorMode.Rest) { error = " \"Internal server error\"}"; @@ -267,12 +244,10 @@ public static IEnumerable V1TestCases() contentLength = 35; statusCode = 500; } - Assert.Equal(statusCode, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":"+error, content); - Assert.Equal(contentLength, response.Content.Headers.ContentLength); - await Task.CompletedTask; + Assert.Equal(statusCode, response.StatusCode); + Assert.Equal("application/json", response.ContentType); + Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); + Assert.Equal(contentLength, response.ContentLength); } } }; @@ -291,11 +266,10 @@ public static IEnumerable V1TestCases() { "Content-Type", "application/json" } } }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - await Task.CompletedTask; - } + Assert.Equal("application/json", response.ContentType); + }, } }; yield return new object[] @@ -308,28 +282,26 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.True(response.Headers.Contains("Date")); + Assert.True(response.Headers.ContainsKey("Date")); if (emulatorMode == ApiGatewayEmulatorMode.Rest) { - Assert.True(response.Headers.Contains("x-amzn-RequestId")); - Assert.True(response.Headers.Contains("x-amz-apigw-id")); - Assert.True(response.Headers.Contains("X-Amzn-Trace-Id")); + Assert.True(response.Headers.ContainsKey("x-amzn-RequestId")); + Assert.True(response.Headers.ContainsKey("x-amz-apigw-id")); + Assert.True(response.Headers.ContainsKey("X-Amzn-Trace-Id")); - Assert.Matches(@"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", response.Headers.GetValues("x-amzn-RequestId").First()); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers.GetValues("x-amz-apigw-id").First()); - Assert.Matches(@"^Root=1-[0-9a-f]{8}-[0-9a-f]{24};Parent=[0-9a-f]{16};Sampled=0;Lineage=1:[0-9a-f]{8}:0$", response.Headers.GetValues("X-Amzn-Trace-Id").First()); + Assert.Matches(@"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", response.Headers["x-amzn-RequestId"]); + Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["x-amz-apigw-id"]); + Assert.Matches(@"^Root=1-[0-9a-f]{8}-[0-9a-f]{24};Parent=[0-9a-f]{16};Sampled=0;Lineage=1:[0-9a-f]{8}:0$", response.Headers["X-Amzn-Trace-Id"]); } else // HttpV1 or HttpV2 { - Assert.True(response.Headers.Contains("Apigw-Requestid")); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers.GetValues("Apigw-Requestid").First()); + Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); + Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); } - - await Task.CompletedTask; - } + }, } }; @@ -349,13 +321,12 @@ public static IEnumerable V2TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal(200, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Hello, World!\"}", content); - } + Assert.Equal(200, response.StatusCode); + Assert.Equal("application/json", response.ContentType); + Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); + }, } }; @@ -369,11 +340,10 @@ public static IEnumerable V2TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal(201, (int)response.StatusCode); - await Task.CompletedTask; - } + Assert.Equal(201, response.StatusCode); + }, } }; @@ -387,22 +357,19 @@ public static IEnumerable V2TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { string error; int contentLength; int statusCode; - error = "\"Internal Server Error\"}"; contentLength = 35; statusCode = 500; - Assert.Equal(statusCode, (int)response.StatusCode); - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":"+error, content); - Assert.Equal(contentLength, response.Content.Headers.ContentLength); - await Task.CompletedTask; - } + Assert.Equal(statusCode, response.StatusCode); + Assert.Equal("application/json", response.ContentType); + Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); + Assert.Equal(contentLength, response.ContentLength); + }, } }; @@ -421,13 +388,11 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - Assert.True(response.Headers.Contains("X-Custom-Header")); - Assert.Equal("CustomValue", response.Headers.GetValues("X-Custom-Header").First()); - await Task.CompletedTask; - } + Assert.Equal("application/json", response.Headers["Content-Type"]); + Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); + }, } }; @@ -442,11 +407,10 @@ public static IEnumerable V2TestCases() Body = "{\"message\":\"Hello, API Gateway v2!\"}", IsBase64Encoded = false }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", content); - } + Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); + }, } }; @@ -461,11 +425,10 @@ public static IEnumerable V2TestCases() Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"message\":\"Hello, API Gateway v2!\"}")), IsBase64Encoded = true }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatormode) => { - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", content); - } + Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); + }, } }; @@ -479,11 +442,10 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal("text/plain; charset=utf-8", response.Content.Headers.ContentType?.ToString()); - await Task.CompletedTask; - } + Assert.Equal("text/plain; charset=utf-8", response.ContentType); + }, } }; @@ -503,13 +465,12 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal("application/json", response.Content.Headers.ContentType?.ToString()); - Assert.Equal("test,shouldhavesecondvalue", response.Headers.GetValues("myheader").First()); - Assert.Equal("secondvalue", response.Headers.GetValues("anotherheader").First()); - await Task.CompletedTask; - } + Assert.Equal("application/json", response.Headers["Content-Type"]); + Assert.Equal("test,shouldhavesecondvalue", response.Headers["myheader"]); + Assert.Equal("secondvalue", response.Headers["anotherheader"]); + }, } }; @@ -527,13 +488,12 @@ public static IEnumerable V2TestCases() { "Content-Type", "application/xml" } } }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.Equal(201, (int)response.StatusCode); - Assert.Equal("application/xml", response.Content.Headers.ContentType?.ToString()); - var content = await response.Content.ReadAsStringAsync(); - Assert.Equal("{\"key\":\"value\"}", content); - } + Assert.Equal(201, response.StatusCode); + Assert.Equal("application/xml", response.ContentType); + Assert.Equal("{\"key\":\"value\"}", ReadResponseBody(response)); + }, } }; @@ -547,23 +507,28 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = async (response, emulatorMode) => + Assertions = (response, emulatorMode) => { - Assert.True(response.Headers.Contains("Date")); - Assert.True(response.Headers.Contains("Apigw-Requestid")); + Assert.True(response.Headers.ContainsKey("Date")); + Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers.GetValues("Apigw-Requestid").First()); - await Task.CompletedTask; - } + Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); + }, } }; } + private static string ReadResponseBody(HttpResponse response) + { + response.Body.Seek(0, SeekOrigin.Begin); + using var reader = new StreamReader(response.Body); + return reader.ReadToEnd(); + } + public class ApiGatewayResponseTestCase { public required object Response { get; set; } - public required Func Assertions { get; set; } + public required Action Assertions { get; set; } } - } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs index 2a8f1ffec..7ef0cf90c 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs @@ -142,11 +142,11 @@ private async Task RunApiGatewayTestInternal( string testName) where T : class { - T actualApiGatewayRequest; - actualApiGatewayRequest = await _snapshots.LoadSnapshot(testName); + T snapshot; + snapshot = await _snapshots.LoadSnapshot(testName); var expectedApiGatewayRequest = await toApiGatewayRequest(testCase.HttpContext, testCase.ApiGatewayRouteConfig); - CompareApiGatewayRequests(expectedApiGatewayRequest, actualApiGatewayRequest); - testCase.Assertions(actualApiGatewayRequest!, emulatorMode); + CompareApiGatewayRequests(expectedApiGatewayRequest, snapshot); + testCase.Assertions(expectedApiGatewayRequest!, emulatorMode); } private void CompareApiGatewayRequests(T expected, T actual) where T : class? diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs index ca4475512..d96429711 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs @@ -6,7 +6,6 @@ using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.Model; using Amazon.Lambda.TestTool.Extensions; -using Amazon.Lambda.TestTool.IntegrationTests.Helpers; using Amazon.Lambda.TestTool.Models; using Xunit; @@ -45,13 +44,12 @@ public async Task ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversio }; // Act - var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + var apiGatewayProxyResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); var testName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + emulatorMode; // Assert - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await _helper.VerifyApiGatewayResponseAsync(apiGatewayProxyResponse, emulatorMode, testName); } [Fact] @@ -73,8 +71,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirect var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); // Assert - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await _helper.VerifyHttpApiV2ResponseAsync(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); } [Theory] @@ -97,10 +94,18 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); Assert.Contains(expectedErrorMessage, convertedResponse.Body); - var (actualResponse, _) = await _helper.ExecuteTestRequest(convertedResponse, emulatorMode, testName); - Assert.Equal(expectedStatusCode, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Contains(expectedErrorMessage, content); + await _helper.VerifyApiGatewayResponseAsync( + convertedResponse, + emulatorMode, + testName, + async httpResponse => + { + Assert.Equal(expectedStatusCode, httpResponse.StatusCode); + + httpResponse.Body.Seek(0, SeekOrigin.Begin); + var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); + Assert.Contains(expectedErrorMessage, content); + }); } /// @@ -159,14 +164,20 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); Assert.Equal("application/json", actualConvertedResponse.Headers["Content-Type"]); - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(actualConvertedResponse, testCaseName); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await _helper.VerifyHttpApiV2ResponseAsync( + actualConvertedResponse, + testCaseName, + async httpResponse => + { + // Additional checks for API Gateway specific behavior + Assert.Equal(200, httpResponse.StatusCode); + + httpResponse.Body.Seek(0, SeekOrigin.Begin); + var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); + Assert.Equal(expectedResponsePayload, content); - // Additional checks for API Gateway specific behavior - Assert.Equal(200, (int)actualResponse.StatusCode); - var actualContent = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal(expectedResponsePayload, actualContent); - Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); + Assert.Equal("application/json", httpResponse.Headers["Content-Type"]); + }); } [Fact] @@ -187,14 +198,20 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsIn Assert.Equal("{\"message\":\"Internal Server Error\"}", convertedResponse.Body); Assert.Equal("application/json", convertedResponse.Headers["Content-Type"]); - var (actualResponse, httpTestResponse) = await _helper.ExecuteTestRequest(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); - await _helper.AssertResponsesEqual(actualResponse, httpTestResponse); + await _helper.VerifyHttpApiV2ResponseAsync( + convertedResponse, + nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError), + async httpResponse => + { + // Additional checks for API Gateway specific behavior + Assert.Equal(500, httpResponse.StatusCode); + + httpResponse.Body.Seek(0, SeekOrigin.Begin); + var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); + Assert.Equal("{\"message\":\"Internal Server Error\"}", content); - // Additional checks for API Gateway specific behavior - Assert.Equal(500, (int)actualResponse.StatusCode); - var content = await actualResponse.Content.ReadAsStringAsync(); - Assert.Equal("{\"message\":\"Internal Server Error\"}", content); - Assert.Equal("application/json", actualResponse.Content.Headers.ContentType?.ToString()); + Assert.Equal("application/json", httpResponse.Headers["Content-Type"]); + }); } [Theory] From 956883064220bc9306b72cf111ee52dbac9d7b36 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 20:34:53 -0400 Subject: [PATCH 5/9] Remove duplicate assertions --- .../ApiGatewayTestHelper.cs | 12 +- .../ApiGatewayResponseExtensionsTests.cs | 12 +- .../Extensions/ApiGatewayResponseTestCases.cs | 164 ------------------ .../InvokeResponseExtensionsTests.cs | 36 +--- 4 files changed, 7 insertions(+), 217 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs index 34845560e..523610b91 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/ApiGatewayTestHelper.cs @@ -23,8 +23,7 @@ public class ApiGatewayTestHelper public async Task VerifyApiGatewayResponseAsync( APIGatewayProxyResponse response, ApiGatewayEmulatorMode emulatorMode, - string snapshotName, - Action? additionalAssertions = null) + string snapshotName) { // Convert response to HttpResponse (simulates what API Gateway would do) var convertedResponse = await ConvertToHttpResponseAsync(response, emulatorMode); @@ -34,15 +33,11 @@ public async Task VerifyApiGatewayResponseAsync( // Compare the responses await AssertResponsesEqual(expectedResponse, convertedResponse); - - // Run any additional assertions - additionalAssertions?.Invoke(convertedResponse); } public async Task VerifyHttpApiV2ResponseAsync( APIGatewayHttpApiV2ProxyResponse response, - string snapshotName, - Action? additionalAssertions = null) + string snapshotName) { // Convert response to HttpResponse (simulates what API Gateway would do) var convertedResponse = await ConvertToHttpResponseAsync(response); @@ -52,9 +47,6 @@ public async Task VerifyHttpApiV2ResponseAsync( // Compare the responses await AssertResponsesEqual(expectedResponse, convertedResponse); - - // Run any additional assertions - additionalAssertions?.Invoke(convertedResponse); } private async Task ConvertToHttpResponseAsync( diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs index d08221d03..f65f4e523 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs @@ -35,11 +35,7 @@ public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayRespon { var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; Assert.NotNull(testResponse); - await _helper.VerifyHttpApiV2ResponseAsync(testResponse, testName, - response => - { - testCase.Assertions(response, ApiGatewayEmulatorMode.HttpV2); - }); + await _helper.VerifyHttpApiV2ResponseAsync(testResponse, testName); } [Fact] @@ -89,11 +85,7 @@ private async Task RunV1Test(ApiGatewayResponseTestCase testCase, ApiGatewayEmul var testResponse = testCase.Response as APIGatewayProxyResponse; Assert.NotNull(testResponse); var testCaseName = testName + emulatorMode; - await _helper.VerifyApiGatewayResponseAsync(testResponse, emulatorMode, testCaseName, - httpResponse => - { - testCase.Assertions(httpResponse, emulatorMode); - }); + await _helper.VerifyApiGatewayResponseAsync(testResponse, emulatorMode, testCaseName); } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs index 082990420..0921fa238 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs @@ -26,12 +26,6 @@ public static IEnumerable V1TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = (response, emulatormode) => - { - Assert.Equal(200, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, } }; @@ -45,10 +39,6 @@ public static IEnumerable V1TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal(201, response.StatusCode); - }, } }; @@ -67,11 +57,6 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); - }, } }; @@ -89,10 +74,6 @@ public static IEnumerable V1TestCases() }, Body = "{\"message\":\"With MultiValueHeaders\"}" }, - Assertions = (response, emulatormode) => - { - Assert.Equal(new[] { "Value1", "Value2" }, response.Headers["X-Multi-Header"]); - }, } }; @@ -107,10 +88,6 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"Hello, World!\"}", IsBase64Encoded = false }, - Assertions = (response, emulatormode) => - { - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, } }; @@ -124,16 +101,6 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = (response, emulatorMode) => - { - if (emulatorMode == ApiGatewayEmulatorMode.HttpV1) - { - Assert.Equal("text/plain; charset=utf-8", response.ContentType); - } else - { - Assert.Equal("application/json", response.ContentType); - } - }, } }; @@ -158,13 +125,6 @@ public static IEnumerable V1TestCases() StatusCode = 200 }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("test,other", response.Headers["myheader"]); - Assert.Equal("secondvalue", response.Headers["anotherheader"]); - Assert.Equal(new[] { "headervalue", "headervalue2" }, response.Headers["headername"]); - }, } }; @@ -189,13 +149,6 @@ public static IEnumerable V1TestCases() Body = "{\"message\":\"With Combined Headers\"}", StatusCode = 200 }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("single-value", response.Headers["X-Custom-Header"]); - Assert.Equal(new[] { "multi-value1", "multi-value2" }, response.Headers["X-Multi-Header"]); - Assert.Equal(new[] { "multi-value1", "multi-value2", "single-value" }, response.Headers["Combined-Header"]); - }, } }; @@ -210,10 +163,6 @@ public static IEnumerable V1TestCases() IsBase64Encoded = false, StatusCode = 200 }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("{\"message\":\"Hello, World!\"}".Length, response.ContentLength); - }, } }; @@ -227,28 +176,6 @@ public static IEnumerable V1TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = (response, emulatorMode) => - { - string error; - int contentLength; - int statusCode; - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - error = " \"Internal server error\"}"; - contentLength = 36; - statusCode = 502; - } - else - { - error = "\"Internal Server Error\"}"; - contentLength = 35; - statusCode = 500; - } - Assert.Equal(statusCode, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); - Assert.Equal(contentLength, response.ContentLength); - } } }; @@ -266,10 +193,6 @@ public static IEnumerable V1TestCases() { "Content-Type", "application/json" } } }, - Assertions = (response, emulatormode) => - { - Assert.Equal("application/json", response.ContentType); - }, } }; yield return new object[] @@ -282,26 +205,6 @@ public static IEnumerable V1TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = (response, emulatorMode) => - { - Assert.True(response.Headers.ContainsKey("Date")); - - if (emulatorMode == ApiGatewayEmulatorMode.Rest) - { - Assert.True(response.Headers.ContainsKey("x-amzn-RequestId")); - Assert.True(response.Headers.ContainsKey("x-amz-apigw-id")); - Assert.True(response.Headers.ContainsKey("X-Amzn-Trace-Id")); - - Assert.Matches(@"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", response.Headers["x-amzn-RequestId"]); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["x-amz-apigw-id"]); - Assert.Matches(@"^Root=1-[0-9a-f]{8}-[0-9a-f]{24};Parent=[0-9a-f]{16};Sampled=0;Lineage=1:[0-9a-f]{8}:0$", response.Headers["X-Amzn-Trace-Id"]); - } - else // HttpV1 or HttpV2 - { - Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); - } - }, } }; @@ -321,12 +224,6 @@ public static IEnumerable V2TestCases() Body = JsonSerializer.Serialize(new { message = "Hello, World!" }), Headers = new Dictionary { { "Content-Type", "application/json" } } }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(200, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":\"Hello, World!\"}", ReadResponseBody(response)); - }, } }; @@ -340,10 +237,6 @@ public static IEnumerable V2TestCases() StatusCode = 201, Body = "{\"message\":\"Created\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(201, response.StatusCode); - }, } }; @@ -357,19 +250,6 @@ public static IEnumerable V2TestCases() StatusCode = 0, Body = "{\"key\":\"This body should be replaced\"}" }, - Assertions = (response, emulatorMode) => - { - string error; - int contentLength; - int statusCode; - error = "\"Internal Server Error\"}"; - contentLength = 35; - statusCode = 500; - Assert.Equal(statusCode, response.StatusCode); - Assert.Equal("application/json", response.ContentType); - Assert.Equal("{\"message\":"+error, ReadResponseBody(response)); - Assert.Equal(contentLength, response.ContentLength); - }, } }; @@ -388,11 +268,6 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("CustomValue", response.Headers["X-Custom-Header"]); - }, } }; @@ -407,10 +282,6 @@ public static IEnumerable V2TestCases() Body = "{\"message\":\"Hello, API Gateway v2!\"}", IsBase64Encoded = false }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); - }, } }; @@ -425,10 +296,6 @@ public static IEnumerable V2TestCases() Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("{\"message\":\"Hello, API Gateway v2!\"}")), IsBase64Encoded = true }, - Assertions = (response, emulatormode) => - { - Assert.Equal("{\"message\":\"Hello, API Gateway v2!\"}", ReadResponseBody(response)); - }, } }; @@ -442,10 +309,6 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Hello, World!" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("text/plain; charset=utf-8", response.ContentType); - }, } }; @@ -465,12 +328,6 @@ public static IEnumerable V2TestCases() }, Body = "{\"message\":\"With Headers\"}" }, - Assertions = (response, emulatorMode) => - { - Assert.Equal("application/json", response.Headers["Content-Type"]); - Assert.Equal("test,shouldhavesecondvalue", response.Headers["myheader"]); - Assert.Equal("secondvalue", response.Headers["anotherheader"]); - }, } }; @@ -488,12 +345,6 @@ public static IEnumerable V2TestCases() { "Content-Type", "application/xml" } } }, - Assertions = (response, emulatorMode) => - { - Assert.Equal(201, response.StatusCode); - Assert.Equal("application/xml", response.ContentType); - Assert.Equal("{\"key\":\"value\"}", ReadResponseBody(response)); - }, } }; @@ -507,28 +358,13 @@ public static IEnumerable V2TestCases() StatusCode = 200, Body = "Test body" }, - Assertions = (response, emulatorMode) => - { - Assert.True(response.Headers.ContainsKey("Date")); - Assert.True(response.Headers.ContainsKey("Apigw-Requestid")); - - Assert.Matches(@"^[A-Za-z0-9_\-]{15}=$", response.Headers["Apigw-Requestid"]); - }, } }; } - private static string ReadResponseBody(HttpResponse response) - { - response.Body.Seek(0, SeekOrigin.Begin); - using var reader = new StreamReader(response.Body); - return reader.ReadToEnd(); - } - public class ApiGatewayResponseTestCase { public required object Response { get; set; } - public required Action Assertions { get; set; } } } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs index d96429711..344f0a9ad 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs @@ -97,15 +97,7 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api await _helper.VerifyApiGatewayResponseAsync( convertedResponse, emulatorMode, - testName, - async httpResponse => - { - Assert.Equal(expectedStatusCode, httpResponse.StatusCode); - - httpResponse.Body.Seek(0, SeekOrigin.Begin); - var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); - Assert.Contains(expectedErrorMessage, content); - }); + testName); } /// @@ -166,18 +158,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa await _helper.VerifyHttpApiV2ResponseAsync( actualConvertedResponse, - testCaseName, - async httpResponse => - { - // Additional checks for API Gateway specific behavior - Assert.Equal(200, httpResponse.StatusCode); - - httpResponse.Body.Seek(0, SeekOrigin.Begin); - var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); - Assert.Equal(expectedResponsePayload, content); - - Assert.Equal("application/json", httpResponse.Headers["Content-Type"]); - }); + testCaseName); } [Fact] @@ -200,18 +181,7 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsIn await _helper.VerifyHttpApiV2ResponseAsync( convertedResponse, - nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError), - async httpResponse => - { - // Additional checks for API Gateway specific behavior - Assert.Equal(500, httpResponse.StatusCode); - - httpResponse.Body.Seek(0, SeekOrigin.Begin); - var content = await new StreamReader(httpResponse.Body).ReadToEndAsync(); - Assert.Equal("{\"message\":\"Internal Server Error\"}", content); - - Assert.Equal("application/json", httpResponse.Headers["Content-Type"]); - }); + nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); } [Theory] From b34edb629f9bc9ffc5a245a76b6abf61c65eeff9 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 20:39:09 -0400 Subject: [PATCH 6/9] rename variables --- .../Extensions/ApiGatewayResponseTestCases.cs | 3 -- .../InvokeResponseExtensionsTests.cs | 32 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs index 0921fa238..302d46d74 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseTestCases.cs @@ -4,9 +4,6 @@ using System.Text; using System.Text.Json; using Amazon.Lambda.APIGatewayEvents; -using Amazon.Lambda.TestTool.Models; -using Microsoft.AspNetCore.Http; -using Xunit; namespace Amazon.Lambda.TestTool.UnitTests.Extensions; diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs index 344f0a9ad..2e6581c91 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs @@ -68,10 +68,10 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirect }; // Act - var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + var apiGatewayHttpApiV2ProxyResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); // Assert - await _helper.VerifyHttpApiV2ResponseAsync(convertedResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); + await _helper.VerifyHttpApiV2ResponseAsync(apiGatewayHttpApiV2ProxyResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion)); } [Theory] @@ -86,16 +86,16 @@ public async Task ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse(Api }; // Act - var convertedResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); + var apiGatewayProxyResponse = invokeResponse.ToApiGatewayProxyResponse(emulatorMode); var testName = nameof(ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponse) + emulatorMode; // Assert - Assert.Equal(expectedStatusCode, convertedResponse.StatusCode); - Assert.Contains(expectedErrorMessage, convertedResponse.Body); + Assert.Equal(expectedStatusCode, apiGatewayProxyResponse.StatusCode); + Assert.Contains(expectedErrorMessage, apiGatewayProxyResponse.Body); await _helper.VerifyApiGatewayResponseAsync( - convertedResponse, + apiGatewayProxyResponse, emulatorMode, testName); } @@ -147,17 +147,17 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_VariousPayloads_ReturnsAsRa }; // Act - var actualConvertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + var apiGatewayHttpApiV2ProxyResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); var testCaseName = nameof(ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversion) + testName; // Assert - Assert.Equal(200, actualConvertedResponse.StatusCode); - Assert.Equal(expectedResponsePayload, actualConvertedResponse.Body); - Assert.Equal("application/json", actualConvertedResponse.Headers["Content-Type"]); + Assert.Equal(200, apiGatewayHttpApiV2ProxyResponse.StatusCode); + Assert.Equal(expectedResponsePayload, apiGatewayHttpApiV2ProxyResponse.Body); + Assert.Equal("application/json", apiGatewayHttpApiV2ProxyResponse.Headers["Content-Type"]); await _helper.VerifyHttpApiV2ResponseAsync( - actualConvertedResponse, + apiGatewayHttpApiV2ProxyResponse, testCaseName); } @@ -172,15 +172,15 @@ public async Task ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsIn }; // Act - var convertedResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); + var apiGatewayHttpApiV2ProxyResponse = invokeResponse.ToApiGatewayHttpApiV2ProxyResponse(); // Assert - Assert.Equal(500, convertedResponse.StatusCode); - Assert.Equal("{\"message\":\"Internal Server Error\"}", convertedResponse.Body); - Assert.Equal("application/json", convertedResponse.Headers["Content-Type"]); + Assert.Equal(500, apiGatewayHttpApiV2ProxyResponse.StatusCode); + Assert.Equal("{\"message\":\"Internal Server Error\"}", apiGatewayHttpApiV2ProxyResponse.Body); + Assert.Equal("application/json", apiGatewayHttpApiV2ProxyResponse.Headers["Content-Type"]); await _helper.VerifyHttpApiV2ResponseAsync( - convertedResponse, + apiGatewayHttpApiV2ProxyResponse, nameof(ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError)); } From e618ec4946527b665fabf963e04ec9771313ca4d Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 14 Apr 2025 20:50:43 -0400 Subject: [PATCH 7/9] update snapshots --- .../Snapshots/BinaryContentHttpV1.json | 26 ++++++++--------- .../Snapshots/BinaryContentRest.json | 28 +++++++++---------- ...odeAsFloat_ReturnsInternalServerError.json | 4 ++- ...ValidResponse_MatchesDirectConversion.json | 4 ++- ...nvalidJson_ReturnsErrorResponseHttpV1.json | 4 ++- ..._InvalidJson_ReturnsErrorResponseRest.json | 4 ++- ...esponse_MatchesDirectConversionHttpV1.json | 4 ++- ...ConversionInvalid_JSON_Partial_Object.json | 4 ++- ...nse_MatchesDirectConversionJSON_Array.json | 4 ++- ...dResponse_MatchesDirectConversionRest.json | 4 ++- ...chesDirectConversionValid_JSON_Object.json | 4 ++- ...sponse_MatchesDirectConversionboolean.json | 4 ++- ...e_MatchesDirectConversionempty_string.json | 4 ++- ...e_MatchesDirectConversionjson_special.json | 4 ++- ...esponse_MatchesDirectConversionnumber.json | 4 ++- ...esponse_MatchesDirectConversionstring.json | 4 ++- ..._MatchesDirectConversionstring_spaces.json | 4 ++- ...tchesDirectConversionstring_unescaped.json | 4 ++- .../Snapshots/V1_APIHeadersHttpV1.json | 4 ++- .../Snapshots/V1_APIHeadersRest.json | 4 ++- ...binesSingleAndMultiValueHeadersHttpV1.json | 4 ++- ...ombinesSingleAndMultiValueHeadersRest.json | 4 ++- ...V1_DefaultsToCorrectContentTYpeHttpV1.json | 4 ++- .../V1_DefaultsToCorrectContentTYpeRest.json | 4 ++- .../V1_HandlesHeadersCorrectlyHttpV1.json | 4 ++- .../V1_HandlesHeadersCorrectlyRest.json | 4 ++- .../V1_HandlesZeroStatusCodeHttpV1.json | 4 ++- .../V1_HandlesZeroStatusCodeRest.json | 4 ++- .../Snapshots/V1_SetsBodyNonBase64HttpV1.json | 4 ++- .../Snapshots/V1_SetsBodyNonBase64Rest.json | 4 ++- .../Snapshots/V1_SetsContentLengthHttpV1.json | 4 ++- .../Snapshots/V1_SetsContentLengthRest.json | 4 ++- .../V1_SetsCorrectStatusCodeHttpV1.json | 4 ++- .../V1_SetsCorrectStatusCodeRest.json | 4 ++- .../Snapshots/V1_SetsHeadersHttpV1.json | 4 ++- .../Snapshots/V1_SetsHeadersRest.json | 4 ++- .../V1_SetsMultiValueHeadersHttpV1.json | 4 ++- .../V1_SetsMultiValueHeadersRest.json | 4 ++- .../Snapshots/V1_SimpleGetRequestHttpV1.json | 26 ++++++++--------- .../Snapshots/V1_SimpleGetRequestRest.json | 28 +++++++++---------- .../V1_SimpleJsonResponseHttpV1.json | 4 ++- .../Snapshots/V1_SimpleJsonResponseRest.json | 4 ++- .../V1_SpecialCharactersInPathHttpV1.json | 26 ++++++++--------- .../V1_SpecialCharactersInPathRest.json | 28 +++++++++---------- .../V1_UnicodeCharactersInPathHttpV1.json | 26 ++++++++--------- .../V1_UnicodeCharactersInPathRest.json | 28 +++++++++---------- .../V1_UrlEncodedQueryStringHttpV1.json | 26 ++++++++--------- .../V1_UrlEncodedQueryStringRest.json | 28 +++++++++---------- .../V1_UsesProvidedContentTypeHttpV1.json | 4 ++- .../V1_UsesProvidedContentTypeRest.json | 4 ++- .../Snapshots/V2_BinaryContent.json | 18 ++++++------ .../V2_DefaultsToTextPlainContentType.json | 4 ++- .../V2_DoesNotOverrideExplicitValues.json | 4 ++- .../Snapshots/V2_HandlesHeadersCorrectly.json | 4 ++- .../Snapshots/V2_HandlesZeroStatusCode.json | 4 ++- .../Snapshots/V2_HttpAPIHeaders.json | 4 ++- .../Snapshots/V2_SetsBodyBase64.json | 4 ++- .../Snapshots/V2_SetsBodyNonBase64.json | 4 ++- .../Snapshots/V2_SetsCorrectStatusCode.json | 4 ++- .../Snapshots/V2_SetsHeaders.json | 4 ++- .../Snapshots/V2_SimpleGetRequest.json | 18 ++++++------ .../Snapshots/V2_SimpleJsonResponse.json | 4 ++- .../Snapshots/V2_SpecialCharactersInPath.json | 18 ++++++------ .../Snapshots/V2_UnicodeCharactersInPath.json | 18 ++++++------ .../Snapshots/V2_UrlEncodedQueryString.json | 18 ++++++------ 65 files changed, 325 insertions(+), 235 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json index d0fcc8837..57728f30c 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentHttpV1.json @@ -5,9 +5,9 @@ "Headers": { "Content-Length": "5", "Content-Type": "application/octet-stream", - "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd88fd-72d8964e1fed2bce3edd5aac", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -18,15 +18,11 @@ "Content-Type": [ "application/octet-stream" ], - "Host": [ - "0awrsfc302.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd88fd-72d8964e1fed2bce3edd5aac" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -42,7 +38,7 @@ "StageVariables": null, "RequestContext": { "Path": "/test3/api/users/123/avatar", - "AccountId": "147997163238", + "AccountId": "ACCOUNT_ID", "ResourceId": "POST /test3/api/users/{userId}/avatar", "Stage": "$default", "RequestId": "JCJXri3_PHcEP_Q=", @@ -54,7 +50,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -64,12 +60,12 @@ }, "ResourcePath": "/test3/api/users/{userId}/avatar", "HttpMethod": "POST", - "ApiId": "0awrsfc302", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJXri3_PHcEP_Q=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "0awrsfc302", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -84,4 +80,6 @@ }, "Body": "AQIDBAU=", "IsBase64Encoded": true -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json index d47c345e0..173e35f87 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/BinaryContentRest.json @@ -4,9 +4,9 @@ "HttpMethod": "POST", "Headers": { "Content-Type": "application/octet-stream", - "Host": "4brwn090q0.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd8927-4b9cc8347ead8aa60c674ac2", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -14,15 +14,11 @@ "Content-Type": [ "application/octet-stream" ], - "Host": [ - "4brwn090q0.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd8927-4b9cc8347ead8aa60c674ac2" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -38,8 +34,8 @@ "StageVariables": null, "RequestContext": { "Path": "/test/test4/api/users/123/avatar", - "AccountId": "147997163238", - "ResourceId": "rz18ez", + "AccountId": "ACCOUNT_ID", + "ResourceId": "RESOURCE_ID", "Stage": "test", "RequestId": "7a1ab4cd-edd9-4437-86d3-7978341c597d", "Identity": { @@ -50,7 +46,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -60,12 +56,12 @@ }, "ResourcePath": "/test4/api/users/{userId}/avatar", "HttpMethod": "POST", - "ApiId": "4brwn090q0", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJePHSSPHcEtwQ=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "4brwn090q0.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "4brwn090q0", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -80,4 +76,6 @@ }, "Body": "AQIDBAU=", "IsBase64Encoded": true -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json index e01088dfd..9c10b683b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_StatusCodeAsFloat_ReturnsInternalServerError.json @@ -18,4 +18,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json index 1a23816c0..709feb687 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayHttpApiV2ProxyResponse_ValidResponse_MatchesDirectConversion.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json index 757c435e8..b1aee45f3 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseHttpV1.json @@ -18,4 +18,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json index 5c31c6d22..581139ae6 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_InvalidJson_ReturnsErrorResponseRest.json @@ -24,4 +24,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json index 97d3d1175..2a69734cc 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionHttpV1.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json index 515a0fc4d..ebc67aa47 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionInvalid_JSON_Partial_Object.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json index 56d2deed4..cc7259d1e 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionJSON_Array.json @@ -18,4 +18,6 @@ "15" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json index 54ce49b8c..338542cac 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionRest.json @@ -24,4 +24,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json index ff75ba372..920c36e31 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionValid_JSON_Object.json @@ -18,4 +18,6 @@ "31" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json index 575cac85b..0231edb25 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionboolean.json @@ -18,4 +18,6 @@ "4" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json index cb2a45beb..5677c163c 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionempty_string.json @@ -18,4 +18,6 @@ "0" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json index 1ebd5e496..78417df32 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionjson_special.json @@ -18,4 +18,6 @@ "21" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json index 12a38b7fe..d248d5512 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionnumber.json @@ -18,4 +18,6 @@ "2" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json index 1421fc076..21d65a329 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring.json @@ -18,4 +18,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json index e83bc3950..973d47910 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_spaces.json @@ -18,4 +18,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json index 643b81ffb..bab8bc76d 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/ToApiGatewayProxyResponse_ValidResponse_MatchesDirectConversionstring_unescaped.json @@ -18,4 +18,6 @@ "4" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json index 09f365cd5..00ee8e260 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersHttpV1.json @@ -18,4 +18,6 @@ "9" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json index 380edca40..3668d5889 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_APIHeadersRest.json @@ -24,4 +24,6 @@ "9" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json index 40ab4ac07..232116d82 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersHttpV1.json @@ -30,4 +30,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json index 7c13d3c95..7ace4927b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_CombinesSingleAndMultiValueHeadersRest.json @@ -36,4 +36,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json index 94a3d4335..1992983f0 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeHttpV1.json @@ -18,4 +18,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json index 009f9a9c5..e97915691 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_DefaultsToCorrectContentTYpeRest.json @@ -24,4 +24,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json index cb2d3ef8b..73e040eef 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyHttpV1.json @@ -28,4 +28,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json index 10c63f4de..85e78f91d 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesHeadersCorrectlyRest.json @@ -34,4 +34,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json index 441416758..5ebcb1caa 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeHttpV1.json @@ -18,4 +18,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json index e84aace44..75c06db80 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_HandlesZeroStatusCodeRest.json @@ -24,4 +24,6 @@ "36" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json index e531a2263..08212191b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64HttpV1.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json index d697e7420..c615513ab 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsBodyNonBase64Rest.json @@ -24,4 +24,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json index edfd10e69..f65b37cf9 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthHttpV1.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json index 44ea21741..b88537014 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsContentLengthRest.json @@ -24,4 +24,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json index a3460a03e..c43af4752 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeHttpV1.json @@ -18,4 +18,6 @@ "21" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json index b50316d1c..c1a989ce4 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsCorrectStatusCodeRest.json @@ -24,4 +24,6 @@ "21" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json index 37dedd724..cc6a435fb 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersHttpV1.json @@ -21,4 +21,6 @@ "26" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json index bac667913..7e1ce9a5e 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsHeadersRest.json @@ -27,4 +27,6 @@ "26" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json index 5620bf9b1..28606f801 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersHttpV1.json @@ -22,4 +22,6 @@ "36" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json index 10f458ffb..8d5ab9c78 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SetsMultiValueHeadersRest.json @@ -28,4 +28,6 @@ "36" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json index 393e55f08..fee9c6b79 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestHttpV1.json @@ -6,11 +6,11 @@ "Content-Length": "0", "Content-Type": "text/plain; charset=utf-8", "Cookie": "session=abc123; theme=dark", - "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "User-Agent": "TestAgent", "X-Amzn-Trace-Id": "Root=1-67fd8937-6cd643e155b4258a556982c5", "X-Custom-Header": "value1", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -24,9 +24,7 @@ "Cookie": [ "session=abc123; theme=dark" ], - "Host": [ - "0awrsfc302.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "User-Agent": [ "TestAgent" ], @@ -36,9 +34,7 @@ "X-Custom-Header": [ "value1" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -65,7 +61,7 @@ "StageVariables": null, "RequestContext": { "Path": "/test1/api/users/123/orders", - "AccountId": "147997163238", + "AccountId": "ACCOUNT_ID", "ResourceId": "POST /test1/api/users/{userId}/orders", "Stage": "$default", "RequestId": "JCJgriq-vHcEPMg=", @@ -77,7 +73,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -87,12 +83,12 @@ }, "ResourcePath": "/test1/api/users/{userId}/orders", "HttpMethod": "POST", - "ApiId": "0awrsfc302", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJgriq-vHcEPMg=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "0awrsfc302", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -107,4 +103,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json index 94fbc7955..4abba0544 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleGetRequestRest.json @@ -5,11 +5,11 @@ "Headers": { "Content-Type": "text/plain; charset=utf-8", "Cookie": "session=abc123; theme=dark", - "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "User-Agent": "TestAgent", "X-Amzn-Trace-Id": "Root=1-67fd87f5-7643e6a875203f06341af04f", "X-Custom-Header": "value1", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -20,9 +20,7 @@ "Cookie": [ "session=abc123; theme=dark" ], - "Host": [ - "s902u1zkkl.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "User-Agent": [ "TestAgent" ], @@ -32,9 +30,7 @@ "X-Custom-Header": [ "value1" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -61,8 +57,8 @@ "StageVariables": null, "RequestContext": { "Path": "/test/test1/api/users/123/orders", - "AccountId": "147997163238", - "ResourceId": "06oou2", + "AccountId": "ACCOUNT_ID", + "ResourceId": "RESOURCE_ID", "Stage": "test", "RequestId": "4acd49e9-9210-4d04-8e04-0f26a4e92537", "Identity": { @@ -73,7 +69,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -83,12 +79,12 @@ }, "ResourcePath": "/test1/api/users/{userId}/orders", "HttpMethod": "POST", - "ApiId": "s902u1zkkl", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCIudEUfPHcEhog=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "s902u1zkkl", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -103,4 +99,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json index ac0c38898..c6815450c 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseHttpV1.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json index c0664b8fb..67dcec0db 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SimpleJsonResponseRest.json @@ -24,4 +24,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json index cd95b17ec..ef2ccd81a 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathHttpV1.json @@ -5,9 +5,9 @@ "Headers": { "Content-Length": "0", "Content-Type": "text/plain; charset=utf-8", - "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd895b-766061a83ad2b27b1782b470", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -18,15 +18,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "0awrsfc302.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd895b-766061a83ad2b27b1782b470" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -43,7 +39,7 @@ "StageVariables": null, "RequestContext": { "Path": "/test5/api/users/**** Doe/orders/Summer Sale 2023", - "AccountId": "147997163238", + "AccountId": "ACCOUNT_ID", "ResourceId": "POST /test5/api/users/{username}/orders/{orderName}", "Stage": "$default", "RequestId": "JCJmXjUAPHcEP4w=", @@ -55,7 +51,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -65,12 +61,12 @@ }, "ResourcePath": "/test5/api/users/{username}/orders/{orderName}", "HttpMethod": "POST", - "ApiId": "0awrsfc302", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJmXjUAPHcEP4w=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "0awrsfc302", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -85,4 +81,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json index 99b10d245..cee2b253a 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_SpecialCharactersInPathRest.json @@ -4,9 +4,9 @@ "HttpMethod": "POST", "Headers": { "Content-Type": "text/plain; charset=utf-8", - "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd8860-650d70a10ef73c6b16106e8d", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -14,15 +14,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "s902u1zkkl.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd8860-650d70a10ef73c6b16106e8d" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -39,8 +35,8 @@ "StageVariables": null, "RequestContext": { "Path": "/test/test5/api/users/****%20Doe/orders/Summer%20Sale%202023", - "AccountId": "147997163238", - "ResourceId": "g76y15", + "AccountId": "ACCOUNT_ID", + "ResourceId": "RESOURCE_ID", "Stage": "test", "RequestId": "dbcb1121-909c-4d1a-aff3-958e94138b79", "Identity": { @@ -51,7 +47,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -61,12 +57,12 @@ }, "ResourcePath": "/test5/api/users/{username}/orders/{orderName}", "HttpMethod": "POST", - "ApiId": "s902u1zkkl", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCI_JHpQvHcEhVw=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "s902u1zkkl", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -81,4 +77,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json index 29b5060c2..0fe4ee2cf 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathHttpV1.json @@ -5,9 +5,9 @@ "Headers": { "Content-Length": "0", "Content-Type": "text/plain; charset=utf-8", - "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd896c-70b58b4501a8b49c5ef26f03", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -18,15 +18,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "0awrsfc302.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd896c-70b58b4501a8b49c5ef26f03" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -43,7 +39,7 @@ "StageVariables": null, "RequestContext": { "Path": "/test6/api/products/\u2615 Coffee/reviews/\uD83D\uDE0A Happy", - "AccountId": "147997163238", + "AccountId": "ACCOUNT_ID", "ResourceId": "POST /test6/api/products/{productName}/reviews/{reviewTitle}", "Stage": "$default", "RequestId": "JCJpDi3HPHcESow=", @@ -55,7 +51,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -65,12 +61,12 @@ }, "ResourcePath": "/test6/api/products/{productName}/reviews/{reviewTitle}", "HttpMethod": "POST", - "ApiId": "0awrsfc302", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJpDi3HPHcESow=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "0awrsfc302", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -85,4 +81,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json index 662d5282b..c7b18fe91 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UnicodeCharactersInPathRest.json @@ -4,9 +4,9 @@ "HttpMethod": "POST", "Headers": { "Content-Type": "text/plain; charset=utf-8", - "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd8892-563c02fe4dcb438f51739a1b", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -14,15 +14,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "s902u1zkkl.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd8892-563c02fe4dcb438f51739a1b" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -39,8 +35,8 @@ "StageVariables": null, "RequestContext": { "Path": "/test/test6/api/products/%E2%98%95%20Coffee/reviews/%F0%9F%98%8A%20Happy", - "AccountId": "147997163238", - "ResourceId": "hafaxt", + "AccountId": "ACCOUNT_ID", + "ResourceId": "RESOURCE_ID", "Stage": "test", "RequestId": "5005340a-1104-4054-98d0-afda9e163eb1", "Identity": { @@ -51,7 +47,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -61,12 +57,12 @@ }, "ResourcePath": "/test6/api/products/{productName}/reviews/{reviewTitle}", "HttpMethod": "POST", - "ApiId": "s902u1zkkl", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJG5GmOvHcEK7g=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "s902u1zkkl", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -81,4 +77,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json index c685151c4..c6e29d61d 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringHttpV1.json @@ -5,9 +5,9 @@ "Headers": { "Content-Length": "0", "Content-Type": "text/plain; charset=utf-8", - "Host": "0awrsfc302.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd894d-3c512d985fc0f8aa38cbeaac", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -18,15 +18,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "0awrsfc302.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd894d-3c512d985fc0f8aa38cbeaac" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -51,7 +47,7 @@ "StageVariables": null, "RequestContext": { "Path": "/test4/api/search", - "AccountId": "147997163238", + "AccountId": "ACCOUNT_ID", "ResourceId": "POST /test4/api/search", "Stage": "$default", "RequestId": "JCJkHhmUPHcEPXA=", @@ -63,7 +59,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -73,12 +69,12 @@ }, "ResourcePath": "/test4/api/search", "HttpMethod": "POST", - "ApiId": "0awrsfc302", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCJkHhmUPHcEPXA=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "0awrsfc302.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "0awrsfc302", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -93,4 +89,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json index c4e154cb2..11caab563 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UrlEncodedQueryStringRest.json @@ -4,9 +4,9 @@ "HttpMethod": "POST", "Headers": { "Content-Type": "text/plain; charset=utf-8", - "Host": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "X-Amzn-Trace-Id": "Root=1-67fd8822-75aa8f5e7a30566958eef084", - "X-Forwarded-For": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, @@ -14,15 +14,11 @@ "Content-Type": [ "text/plain; charset=utf-8" ], - "Host": [ - "s902u1zkkl.execute-api.us-west-2.amazonaws.com" - ], + "Host": ["EXAMPLE.execute-api.REGION.amazonaws.com"], "X-Amzn-Trace-Id": [ "Root=1-67fd8822-75aa8f5e7a30566958eef084" ], - "X-Forwarded-For": [ - "141.149.44.5" - ], + "X-Forwarded-For": ["IP_ADDRESS"], "X-Forwarded-Port": [ "443" ], @@ -47,8 +43,8 @@ "StageVariables": null, "RequestContext": { "Path": "/test/test4/api/search", - "AccountId": "147997163238", - "ResourceId": "3x3a3q", + "AccountId": "ACCOUNT_ID", + "ResourceId": "RESOURCE_ID", "Stage": "test", "RequestId": "bc5e4f00-8cfb-4473-83c7-e6e1735ee418", "Identity": { @@ -59,7 +55,7 @@ "ApiKey": null, "ApiKeyId": null, "AccessKey": null, - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "CognitoAuthenticationType": null, "CognitoAuthenticationProvider": null, "UserArn": null, @@ -69,12 +65,12 @@ }, "ResourcePath": "/test4/api/search", "HttpMethod": "POST", - "ApiId": "s902u1zkkl", + "ApiId": "EXAMPLE", "ExtendedRequestId": "JCI1hFtPPHcEDUw=", "ConnectionId": null, "ConnectedAt": 0, - "DomainName": "s902u1zkkl.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "s902u1zkkl", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "EventType": null, "MessageId": null, "RouteKey": null, @@ -89,4 +85,6 @@ }, "Body": null, "IsBase64Encoded": false -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json index 8068c33c7..4b5a1c50d 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeHttpV1.json @@ -18,4 +18,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json index 80ad1c99b..367da5bfe 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V1_UsesProvidedContentTypeRest.json @@ -24,4 +24,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json index 9f9b75be9..32c540c68 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_BinaryContent.json @@ -7,24 +7,24 @@ "Headers": { "content-length": "5", "content-type": "application/octet-stream", - "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "x-amzn-trace-id": "Root=1-67fd88b8-2f95df5a03c1bc3a6168b6d8", - "x-forwarded-for": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "x-forwarded-port": "443", "x-forwarded-proto": "https" }, "QueryStringParameters": null, "RequestContext": { - "AccountId": "147997163238", - "ApiId": "7y6qzvvbof", + "AccountId": "ACCOUNT_ID", + "ApiId": "EXAMPLE", "Authorizer": null, - "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "7y6qzvvbof", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "Http": { "Method": "POST", "Path": "/test11/api/users/123/avatar", "Protocol": "HTTP/1.1", - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "UserAgent": "" }, "RequestId": "JCJM3j95PHcEJHg=", @@ -41,4 +41,6 @@ }, "IsBase64Encoded": true, "StageVariables": null -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json index 0003327f9..9abdb6221 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DefaultsToTextPlainContentType.json @@ -18,4 +18,6 @@ "13" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json index d65a3460f..6ba107677 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_DoesNotOverrideExplicitValues.json @@ -18,4 +18,6 @@ "15" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json index 13b6a0bc0..69ead7397 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesHeadersCorrectly.json @@ -24,4 +24,6 @@ "26" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json index cf9ba6661..2a18f512c 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HandlesZeroStatusCode.json @@ -18,4 +18,6 @@ "35" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json index 7cd0fbb9e..a0c208646 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_HttpAPIHeaders.json @@ -18,4 +18,6 @@ "9" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json index 1171b40c0..df8af3852 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyBase64.json @@ -18,4 +18,6 @@ "36" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json index c7a0e3901..2013cf99b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsBodyNonBase64.json @@ -18,4 +18,6 @@ "36" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json index 3bbd2e6ad..64039de16 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsCorrectStatusCode.json @@ -18,4 +18,6 @@ "21" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json index 6e8a971f2..c1e3a7f77 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SetsHeaders.json @@ -21,4 +21,6 @@ "26" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json index 28deb4c69..0433a08b2 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleGetRequest.json @@ -11,11 +11,11 @@ "accept": "text/html, application/json", "content-length": "0", "content-type": "text/plain; charset=utf-8", - "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "user-agent": "TestAgent", "x-amzn-trace-id": "Root=1-67fd88a4-127eb8e773d2bb6f7df47ab6", "x-custom-header": "value1", - "x-forwarded-for": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "x-forwarded-port": "443", "x-forwarded-proto": "https" }, @@ -24,16 +24,16 @@ "tag": "important,urgent" }, "RequestContext": { - "AccountId": "147997163238", - "ApiId": "7y6qzvvbof", + "AccountId": "ACCOUNT_ID", + "ApiId": "EXAMPLE", "Authorizer": null, - "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "7y6qzvvbof", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "Http": { "Method": "POST", "Path": "/test9/api/users/123/orders", "Protocol": "HTTP/1.1", - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "UserAgent": "TestAgent" }, "RequestId": "JCJJxhz4PHcEJgQ=", @@ -50,4 +50,6 @@ }, "IsBase64Encoded": false, "StageVariables": null -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json index 0434de255..6f3b8cf3b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SimpleJsonResponse.json @@ -18,4 +18,6 @@ "27" ] } -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json index c2f9a0312..06a10a2a7 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_SpecialCharactersInPath.json @@ -7,24 +7,24 @@ "Headers": { "content-length": "0", "content-type": "text/plain; charset=utf-8", - "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "x-amzn-trace-id": "Root=1-67fd88db-518e8b296009540c739c0ca7", - "x-forwarded-for": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "x-forwarded-port": "443", "x-forwarded-proto": "https" }, "QueryStringParameters": null, "RequestContext": { - "AccountId": "147997163238", - "ApiId": "7y6qzvvbof", + "AccountId": "ACCOUNT_ID", + "ApiId": "EXAMPLE", "Authorizer": null, - "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "7y6qzvvbof", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "Http": { "Method": "POST", "Path": "/test13/api/users/**** Doe/orders/Summer Sale 2023", "Protocol": "HTTP/1.1", - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "UserAgent": "" }, "RequestId": "JCJSViW5PHcESow=", @@ -42,4 +42,6 @@ }, "IsBase64Encoded": false, "StageVariables": null -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json index f96252162..6796b4a8f 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UnicodeCharactersInPath.json @@ -7,24 +7,24 @@ "Headers": { "content-length": "0", "content-type": "text/plain; charset=utf-8", - "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "x-amzn-trace-id": "Root=1-67fd88e9-487b329f49f6278e32bb642c", - "x-forwarded-for": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "x-forwarded-port": "443", "x-forwarded-proto": "https" }, "QueryStringParameters": null, "RequestContext": { - "AccountId": "147997163238", - "ApiId": "7y6qzvvbof", + "AccountId": "ACCOUNT_ID", + "ApiId": "EXAMPLE", "Authorizer": null, - "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "7y6qzvvbof", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "Http": { "Method": "POST", "Path": "/test14/api/products/\u2615 Coffee/reviews/\uD83D\uDE0A Happy", "Protocol": "HTTP/1.1", - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "UserAgent": "" }, "RequestId": "JCJUkhKBvHcESVw=", @@ -42,4 +42,6 @@ }, "IsBase64Encoded": false, "StageVariables": null -} \ No newline at end of file +} + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json index 3ab34cfdc..c53399786 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Snapshots/V2_UrlEncodedQueryString.json @@ -7,9 +7,9 @@ "Headers": { "content-length": "0", "content-type": "text/plain; charset=utf-8", - "host": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", + "Host": "EXAMPLE.execute-api.REGION.amazonaws.com", "x-amzn-trace-id": "Root=1-67fd88cb-4981526a50466e9f2be0fbed", - "x-forwarded-for": "141.149.44.5", + "X-Forwarded-For": "IP_ADDRESS", "x-forwarded-port": "443", "x-forwarded-proto": "https" }, @@ -18,16 +18,16 @@ "tag": "C# Programming,.NET Core" }, "RequestContext": { - "AccountId": "147997163238", - "ApiId": "7y6qzvvbof", + "AccountId": "ACCOUNT_ID", + "ApiId": "EXAMPLE", "Authorizer": null, - "DomainName": "7y6qzvvbof.execute-api.us-west-2.amazonaws.com", - "DomainPrefix": "7y6qzvvbof", + "DomainName": "EXAMPLE.execute-api.REGION.amazonaws.com", + "DomainPrefix": "EXAMPLE", "Http": { "Method": "POST", "Path": "/test12/api/search", "Protocol": "HTTP/1.1", - "SourceIp": "141.149.44.5", + "SourceIp": "IP_ADDRESS", "UserAgent": "" }, "RequestId": "JCJP4iwYPHcEJgQ=", @@ -42,4 +42,6 @@ "PathParameters": null, "IsBase64Encoded": false, "StageVariables": null -} \ No newline at end of file +} + + From 4865dbc3921167fd81374833892d75c84fb3eada Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Tue, 15 Apr 2025 10:06:45 -0400 Subject: [PATCH 8/9] update name of test --- .../Extensions/ApiGatewayResponseExtensionsTests.cs | 6 +++--- .../Extensions/HttpContextExtensionsTests.cs | 9 +++------ .../Extensions/InvokeResponseExtensionsTests.cs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs index f65f4e523..ba5d7f7aa 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/ApiGatewayResponseExtensionsTests.cs @@ -17,21 +17,21 @@ public class ApiGatewayResponseExtensionsTests [Theory] [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) + public async Task APIGatewayV1_REST(string testName, ApiGatewayResponseTestCase testCase) { await RunV1Test(testCase, ApiGatewayEmulatorMode.Rest, testName); } [Theory] [MemberData(nameof(V1TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) + public async Task APIGatewayV1_HTTP(string testName, ApiGatewayResponseTestCase testCase) { await RunV1Test(testCase, ApiGatewayEmulatorMode.HttpV1, testName); } [Theory] [MemberData(nameof(V2TestCases), MemberType = typeof(ApiGatewayResponseTestCases))] - public async Task IntegrationTest_APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) + public async Task APIGatewayV2(string testName, ApiGatewayResponseTestCase testCase) { var testResponse = testCase.Response as APIGatewayHttpApiV2ProxyResponse; Assert.NotNull(testResponse); diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs index 7ef0cf90c..eff9c3338 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/HttpContextExtensionsTests.cs @@ -23,8 +23,7 @@ public HttpContextExtensionsTests() [Theory] [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCase testCase) + public Task APIGatewayV1_REST(string testName, HttpContextTestCase testCase) { var testCaseName = testName + ApiGatewayEmulatorMode.Rest; return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.Rest, testCaseName); @@ -32,8 +31,7 @@ public Task IntegrationTest_APIGatewayV1_REST(string testName, HttpContextTestCa [Theory] [MemberData(nameof(V1TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) + public Task APIGatewayV1_HTTP(string testName, HttpContextTestCase testCase) { var testCaseName = testName + ApiGatewayEmulatorMode.HttpV1; @@ -42,8 +40,7 @@ public Task IntegrationTest_APIGatewayV1_HTTP(string testName, HttpContextTestCa [Theory] [MemberData(nameof(V2TestCases), MemberType = typeof(HttpContextTestCases))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "xUnit1026:Theory methods should use all of their parameters")] - public Task IntegrationTest_APIGatewayV2(string testName, HttpContextTestCase testCase) + public Task APIGatewayV2(string testName, HttpContextTestCase testCase) { return RunApiGatewayTest(testCase, ApiGatewayEmulatorMode.HttpV2, testName); } diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs index 2e6581c91..f07f70a47 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Extensions/InvokeResponseExtensionsTests.cs @@ -12,7 +12,7 @@ namespace Amazon.Lambda.TestTool.UnitTests.Extensions; /// -/// Integration tests for InvokeResponseExtensions. +/// Unit tests for InvokeResponseExtensions. /// /// /// Developer's Note: From 1aa60ac5207e51779fa64e2568b4602ab12536f6 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Wed, 16 Apr 2025 11:58:20 -0400 Subject: [PATCH 9/9] add docs --- .../SnapshotHelper/ApiGatewayTestSnapshot.cs | 19 ++++++++++++ .../SnapshotHelper/SnapshotTestHelper.cs | 30 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs index 7b23fb5ec..c3e81f68b 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/ApiGatewayTestSnapshot.cs @@ -1,11 +1,24 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + using System.Net; using System.Text.Json; using System.Text.Json.Serialization; namespace Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; +/// +/// Provides custom JSON conversion for HttpResponseMessage objects. +/// public class HttpResponseMessageConverter : JsonConverter { + /// + /// Reads and converts JSON to an HttpResponseMessage object. + /// + /// The Utf8JsonReader to read data from. + /// The type of object to convert. + /// An object that specifies serialization options. + /// The converted HttpResponseMessage. public override HttpResponseMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var document = JsonDocument.ParseValue(ref reader); @@ -42,6 +55,12 @@ public override HttpResponseMessage Read(ref Utf8JsonReader reader, Type typeToC return response; } + /// + /// Writes an HttpResponseMessage object to JSON. + /// + /// The Utf8JsonWriter to write to. + /// The HttpResponseMessage to convert. + /// An object that specifies serialization options. public override void Write(Utf8JsonWriter writer, HttpResponseMessage value, JsonSerializerOptions options) { writer.WriteStartObject(); diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs index 00e7648b9..1ff5a204a 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/SnapshotHelper/SnapshotTestHelper.cs @@ -4,11 +4,20 @@ using System.Text.Json; namespace Amazon.Lambda.TestTool.UnitTests.SnapshotHelper; + +/// +/// Provides functionality for saving and loading snapshot tests, primarily used for testing purposes. +/// public class SnapshotTestHelper { private readonly string _snapshotDirectory; private readonly JsonSerializerOptions _serializerOptions; + /// + /// Initializes a new instance of the SnapshotTestHelper class. + /// + /// Custom JSON serializer options. If null, default options with indented writing will be used. + /// The directory name where snapshots will be stored. Defaults to "Snapshots". public SnapshotTestHelper(JsonSerializerOptions? serializerOptions = null, string snapshotDirectory = "Snapshots") { var projectDir = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "../../../")); @@ -19,6 +28,13 @@ public SnapshotTestHelper(JsonSerializerOptions? serializerOptions = null, strin }; } + /// + /// Saves a snapshot of the specified value to a JSON file. + /// + /// The type of the value to be saved. + /// The value to save as a snapshot. + /// The name of the snapshot file (without extension). + /// A task that represents the asynchronous save operation. public async Task SaveSnapshot(T value, string snapshotName) { Directory.CreateDirectory(_snapshotDirectory); @@ -27,6 +43,13 @@ public async Task SaveSnapshot(T value, string snapshotName) await File.WriteAllTextAsync(filePath, serialized); } + /// + /// Loads a snapshot from a JSON file and deserializes it to the specified type. + /// + /// The type to deserialize the snapshot into. + /// The name of the snapshot file (without extension). + /// The deserialized snapshot object. + /// Thrown when the specified snapshot file does not exist. public async Task LoadSnapshot(string snapshotName) { var filePath = GetSnapshotPath(snapshotName); @@ -36,9 +59,14 @@ public async Task LoadSnapshot(string snapshotName) } var content = await File.ReadAllTextAsync(filePath); - return JsonSerializer.Deserialize(content, _serializerOptions); + return JsonSerializer.Deserialize(content, _serializerOptions)!; } + /// + /// Gets the full file path for a snapshot file. + /// + /// The name of the snapshot file (without extension). + /// The full file path including the .json extension. private string GetSnapshotPath(string snapshotName) => Path.Combine(_snapshotDirectory, $"{snapshotName}.json"); }