Skip to content

Commit

Permalink
Fixed an issue where delimited JSON string payload was not parsed pro…
Browse files Browse the repository at this point in the history
…perly by Lambda Test Tool.
  • Loading branch information
ashishdhingra committed Oct 29, 2024
1 parent 5d11116 commit 10af223
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputType>Exe</OutputType>
<Description>A tool to help debug and test your .NET Core AWS Lambda functions locally.</Description>
<LangVersion>Latest</LangVersion>
<VersionPrefix>0.15.2</VersionPrefix>
<VersionPrefix>0.15.3</VersionPrefix>
<Product>AWS .NET Lambda Test Tool</Product>
<Copyright>Apache 2</Copyright>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Description>A tool to help debug and test your .NET 6.0 AWS Lambda functions locally.</Description>
<VersionPrefix>0.15.2</VersionPrefix>
<VersionPrefix>0.15.3</VersionPrefix>
<Product>AWS .NET Lambda Test Tool</Product>
<Copyright>Apache 2</Copyright>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Description>A tool to help debug and test your .NET 7.0 AWS Lambda functions locally.</Description>
<VersionPrefix>0.15.2</VersionPrefix>
<VersionPrefix>0.15.3</VersionPrefix>
<Product>AWS .NET Lambda Test Tool</Product>
<Copyright>Apache 2</Copyright>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Description>A tool to help debug and test your .NET 8.0 AWS Lambda functions locally.</Description>
<VersionPrefix>0.15.2</VersionPrefix>
<VersionPrefix>0.15.3</VersionPrefix>
<Product>AWS .NET Lambda Test Tool</Product>
<Copyright>Apache 2</Copyright>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ private static string DeterminePayload(LocalLambdaOptions localLambdaOptions, Co
}
}

// Enclose simple string payload in double quotes so that it's parsed properly by Lambda JSON serializer.
if (!payload.StartsWith("{") && !payload.StartsWith("\""))
{
payload = "\"" + payload + "\"";
}

return payload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Amazon.Lambda.TestTool.Tests
{
public class NoUiStartupTests
{


[Fact]
public void DirectFunctionCallFromConfig()
{
Expand Down Expand Up @@ -106,6 +104,26 @@ public void DirectFunctionCallFromConfigWithDisableLogs()
Assert.Equal("\"HELLO WORLD\"", runConfiguration.OutputWriter.ToString());
}

[Fact]
public void DirectFunctionCallNonDelimitedPayloadStringFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");

TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "hello WORLD" }, runConfiguration);
Assert.Contains("HELLO WORLD", runConfiguration.OutputWriter.ToString());
}

[Fact]
public void DirectFunctionCallSingleQuoteDelimitedPayloadStringFromConfig()
{
var runConfiguration = CreateRunConfiguration();
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");

TestToolStartup.Startup("Unit Tests", null, new string[] { "--path", buildPath, "--no-ui", "--payload", "'hello WORLD'" }, runConfiguration);
Assert.Contains("'HELLO WORLD'", runConfiguration.OutputWriter.ToString());
}

private TestToolStartup.RunConfiguration CreateRunConfiguration()
{
return new TestToolStartup.RunConfiguration
Expand Down

0 comments on commit 10af223

Please sign in to comment.