From 10af2235e0c73830394dcc9825f0a6c9bb539ca6 Mon Sep 17 00:00:00 2001 From: Ashish Dhingra <67916761+ashishdhingra@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:37:18 -0700 Subject: [PATCH] Fixed an issue where delimited JSON string payload was not parsed properly by Lambda Test Tool. --- ...Amazon.Lambda.TestTool.BlazorTester.csproj | 2 +- ...Lambda.TestTool.BlazorTester60-pack.csproj | 2 +- ...Lambda.TestTool.BlazorTester70-pack.csproj | 2 +- ...Lambda.TestTool.BlazorTester80-pack.csproj | 2 +- .../Amazon.Lambda.TestTool/TestToolStartup.cs | 6 +++++ .../NoUiStartupTests.cs | 22 +++++++++++++++++-- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester.csproj b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester.csproj index a42529f0d..f31070133 100644 --- a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester.csproj +++ b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester.csproj @@ -6,7 +6,7 @@ Exe A tool to help debug and test your .NET Core AWS Lambda functions locally. Latest - 0.15.2 + 0.15.3 AWS .NET Lambda Test Tool Apache 2 AWS;Amazon;Lambda diff --git a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester60-pack.csproj b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester60-pack.csproj index 246220bb6..2154dd0ea 100644 --- a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester60-pack.csproj +++ b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester60-pack.csproj @@ -5,7 +5,7 @@ Exe A tool to help debug and test your .NET 6.0 AWS Lambda functions locally. - 0.15.2 + 0.15.3 AWS .NET Lambda Test Tool Apache 2 AWS;Amazon;Lambda diff --git a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester70-pack.csproj b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester70-pack.csproj index 27bab1a46..72e4274ae 100644 --- a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester70-pack.csproj +++ b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester70-pack.csproj @@ -5,7 +5,7 @@ Exe A tool to help debug and test your .NET 7.0 AWS Lambda functions locally. - 0.15.2 + 0.15.3 AWS .NET Lambda Test Tool Apache 2 AWS;Amazon;Lambda diff --git a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj index 8880e15d7..48337ebcd 100644 --- a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj +++ b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool.BlazorTester/Amazon.Lambda.TestTool.BlazorTester80-pack.csproj @@ -5,7 +5,7 @@ Exe A tool to help debug and test your .NET 8.0 AWS Lambda functions locally. - 0.15.2 + 0.15.3 AWS .NET Lambda Test Tool Apache 2 AWS;Amazon;Lambda diff --git a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/TestToolStartup.cs b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/TestToolStartup.cs index b130addb9..eabeb7333 100644 --- a/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/TestToolStartup.cs +++ b/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/TestToolStartup.cs @@ -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; } diff --git a/Tools/LambdaTestTool/tests/Amazon.Lambda.TestTool.Tests/NoUiStartupTests.cs b/Tools/LambdaTestTool/tests/Amazon.Lambda.TestTool.Tests/NoUiStartupTests.cs index 17c9fc651..98069ca1f 100644 --- a/Tools/LambdaTestTool/tests/Amazon.Lambda.TestTool.Tests/NoUiStartupTests.cs +++ b/Tools/LambdaTestTool/tests/Amazon.Lambda.TestTool.Tests/NoUiStartupTests.cs @@ -10,8 +10,6 @@ namespace Amazon.Lambda.TestTool.Tests { public class NoUiStartupTests { - - [Fact] public void DirectFunctionCallFromConfig() { @@ -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