Skip to content

flaky tests testing -please ignore #2025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public sealed class RunCommandSettings : CommandSettings
{
/// <summary>
/// The hostname or IP address used for the test tool's web interface.
/// Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.
/// Any host other than an explicit IP address or 127.0.0.1 (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.
/// </summary>
[CommandOption("--lambda-emulator-host <HOST>")]
[Description(
"The hostname or IP address used for the test tool's web interface. Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.")]
"The hostname or IP address used for the test tool's web interface. Any host other than an explicit IP address or 127.0.0.1 (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.")]
[DefaultValue(Constants.DefaultLambdaEmulatorHost)]
public string LambdaEmulatorHost { get; set; } = Constants.DefaultLambdaEmulatorHost;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class Constants
/// <summary>
/// The default hostname used for the Lambda Test Tool.
/// </summary>
public const string DefaultLambdaEmulatorHost = "localhost";
public const string DefaultLambdaEmulatorHost = "127.0.0.1";

/// <summary>
/// The default mode for the API Gateway Emulator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.3" />
Expand All @@ -24,6 +31,13 @@
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="XUnit.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Castle.Core" Version="5.1.1" />

<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// // SPDX-License-Identifier: Apache-2.0

using Xunit;
// using Xunit;

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

}
}
// }
// }
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.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 System.Text.Json;
using Amazon.Lambda.TestTool.Extensions;
using Amazon.Lambda.TestTool.Models;
using System.Text;
using Xunit;
// 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 Xunit;

namespace Amazon.Lambda.TestTool.IntegrationTests
{
[Collection("ApiGateway Integration Tests")]
public class ApiGatewayResponseExtensionsAdditionalTests
{
private readonly ApiGatewayIntegrationTestFixture _fixture;
private readonly HttpClient _httpClient;
// namespace Amazon.Lambda.TestTool.IntegrationTests
// {
// [Collection("ApiGateway Integration Tests")]
// public class ApiGatewayResponseExtensionsAdditionalTests
// {
// private readonly ApiGatewayIntegrationTestFixture _fixture;
// private readonly HttpClient _httpClient;

public ApiGatewayResponseExtensionsAdditionalTests(ApiGatewayIntegrationTestFixture fixture)
{
_fixture = fixture;
_httpClient = new HttpClient();
}
// public ApiGatewayResponseExtensionsAdditionalTests(ApiGatewayIntegrationTestFixture fixture)
// {
// _fixture = fixture;
// _httpClient = new HttpClient();
// }

[Fact]
public async Task ToHttpResponse_RestAPIGatewayV1DecodesBase64()
{
var testResponse = new APIGatewayProxyResponse
{
StatusCode = 200,
Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("test")),
IsBase64Encoded = true
};
// [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);
// 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)));
await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response);
Assert.Equal(200, (int)actualResponse.StatusCode);
var content = await actualResponse.Content.ReadAsStringAsync();
Assert.Equal("test", content);
}
// 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)));
// await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response);
// Assert.Equal(200, (int)actualResponse.StatusCode);
// var content = await actualResponse.Content.ReadAsStringAsync();
// 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
};
// [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);
// 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)));
// 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)));

await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response);
Assert.Equal(200, (int)actualResponse.StatusCode);
var content = await actualResponse.Content.ReadAsStringAsync();
Assert.Equal("test", content);
}
}
}
// await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpContext.Response);
// Assert.Equal(200, (int)actualResponse.StatusCode);
// var content = await actualResponse.Content.ReadAsStringAsync();
// Assert.Equal("test", content);
// }
// }
// }
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.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;
// 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
{
[Collection("ApiGateway Integration Tests")]
public class ApiGatewayResponseExtensionsTests
{
private readonly ApiGatewayIntegrationTestFixture _fixture;
// namespace Amazon.Lambda.TestTool.IntegrationTests
// {
// [Collection("ApiGateway Integration Tests")]
// public class ApiGatewayResponseExtensionsTests
// {
// private readonly ApiGatewayIntegrationTestFixture _fixture;

public ApiGatewayResponseExtensionsTests(ApiGatewayIntegrationTestFixture fixture)
{
_fixture = fixture;
}
// public ApiGatewayResponseExtensionsTests(ApiGatewayIntegrationTestFixture fixture)
// {
// _fixture = fixture;
// }

[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 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;
});
}
// [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 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;
// });
// }

[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 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;
});
}
// [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 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;
// });
// }

[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 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;
});
}
// [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 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;
// });
// }

private async Task RunV1Test(ApiGatewayResponseTestCase testCase, string apiUrl, ApiGatewayEmulatorMode emulatorMode)
{
var testResponse = testCase.Response as APIGatewayProxyResponse;
Assert.NotNull(testResponse);
var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, apiUrl, emulatorMode);
await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse);
await testCase.IntegrationAssertions(actualResponse, emulatorMode);
}
}
}
// private async Task RunV1Test(ApiGatewayResponseTestCase testCase, string apiUrl, ApiGatewayEmulatorMode emulatorMode)
// {
// var testResponse = testCase.Response as APIGatewayProxyResponse;
// Assert.NotNull(testResponse);
// var (actualResponse, httpTestResponse) = await _fixture.ApiGatewayTestHelper.ExecuteTestRequest(testResponse, apiUrl, emulatorMode);
// await _fixture.ApiGatewayTestHelper.AssertResponsesEqual(actualResponse, httpTestResponse);
// await testCase.IntegrationAssertions(actualResponse, emulatorMode);
// }
// }
// }
Loading
Loading