Skip to content

chore: Update test tool tests to not use env vars for lambda runtime api #1992

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

Merged
merged 1 commit into from
Feb 26, 2025
Merged
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 @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.3" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
<PackageReference Include="AWSSDK.APIGateway" Version="3.7.401.19" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ public async Task TestLambdaToUpperV2()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaToUpperV2: {env}");
testOutputHelper.WriteLine($"TestLambdaToUpperV2");
return new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = 200,
Body = request.Body.ToUpper()
};
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/testfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/testfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down Expand Up @@ -83,8 +82,7 @@ public async Task TestLambdaToUpperRest()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaToUpperRest: {env}");
testOutputHelper.WriteLine($"TestLambdaToUpperRest");
return new APIGatewayProxyResponse()
{
StatusCode = 200,
Expand All @@ -93,8 +91,8 @@ public async Task TestLambdaToUpperRest()
};
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/testfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/testfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down Expand Up @@ -125,8 +123,7 @@ public async Task TestLambdaToUpperV1()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaToUpperV1: {env}");
testOutputHelper.WriteLine($"TestLambdaToUpperV1");
return new APIGatewayProxyResponse()
{
StatusCode = 200,
Expand All @@ -135,8 +132,8 @@ public async Task TestLambdaToUpperV1()
};
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/testfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/testfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down Expand Up @@ -167,8 +164,7 @@ public async Task TestLambdaBinaryResponse()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaBinaryResponse: {env}");
testOutputHelper.WriteLine($"TestLambdaBinaryResponse");
// Create a simple binary pattern (for example, counting bytes from 0 to 255)
byte[] binaryData = new byte[256];
for (int i = 0; i < 256; i++)
Expand All @@ -188,8 +184,8 @@ public async Task TestLambdaBinaryResponse()
};
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/binaryfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/binaryfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down Expand Up @@ -226,13 +222,12 @@ public async Task TestLambdaReturnString()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaReturnString: {env}");
testOutputHelper.WriteLine($"TestLambdaReturnString");
return request.Body.ToUpper();
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/stringfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/stringfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down Expand Up @@ -263,17 +258,16 @@ public async Task TestLambdaWithNullEndpoint()
await WaitForGatewayHealthCheck(apiGatewayPort);
var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) =>
{
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
testOutputHelper.WriteLine($"TestLambdaWithNullEndpoint: {env}");
testOutputHelper.WriteLine($"TestLambdaWithNullEndpoint");
return new APIGatewayHttpApiV2ProxyResponse
{
StatusCode = 200,
Body = request.Body.ToUpper()
};
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/testfunction");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/testfunction")
.Build()
.RunAsync(_cancellationTokenSource.Token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.2" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.3" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageReference Include="AWSSDK.Lambda" Version="3.7.411.18" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ namespace Amazon.Lambda.TestTool.UnitTests;

public class RuntimeApiTests
{
#if DEBUG
[Fact]
#else
[Fact(Skip = "Skipping this test as it is not working properly.")]
#endif
[RetryFact]
public async Task AddEventToDataStore()
{
const string functionName = "FunctionFoo";
Expand Down Expand Up @@ -62,10 +58,10 @@ public async Task AddEventToDataStore()
return input.ToUpper();
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync(cancellationTokenSource.Token);
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}")
.Build()
.RunAsync(cancellationTokenSource.Token);

await Task.Delay(2_000, cancellationTokenSource.Token);
Assert.True(handlerCalled);
Expand Down Expand Up @@ -96,10 +92,10 @@ public async Task InvokeRequestResponse()
return input.ToUpper();
};

Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync(cancellationTokenSource.Token);
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}")
.Build()
.RunAsync(cancellationTokenSource.Token);

var lambdaClient = ConstructLambdaServiceClient(testToolProcess.ServiceUrl);

Expand Down
Loading