From 24795ec7a6302ba7ab8a4d8ac8e120e5cd2f29da Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Wed, 4 Dec 2024 15:36:30 -0500 Subject: [PATCH] add packaging of runtime --- .../Amazon.Lambda.TestTool.csproj | 7 ++- .../PackagingTests.cs | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj index 45be7c43f..f8e05697c 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj @@ -15,9 +15,14 @@ + - + + + + + diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs new file mode 100644 index 000000000..21c95c655 --- /dev/null +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs @@ -0,0 +1,59 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using Xunit; + +namespace Amazon.Lambda.TestTool.UnitTests; + +public class PackagingTests +{ + [Fact] + public void VerifyPackageContentsHasRuntimeSupport() + { + string projectPath = Path.Combine(FindSolutionRoot(), "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj"); + + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = $"pack {projectPath} -c Release", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + string output = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + Assert.Equal(0, process.ExitCode); + + string packagePath = Directory.GetFiles(Path.GetDirectoryName(projectPath), "*.nupkg", SearchOption.AllDirectories)[0]; + + using (var archive = ZipFile.OpenRead(packagePath)) + { + var runtimeSupportDllEntry = archive.GetEntry("content/Amazon.Lambda.RuntimeSupport.dll"); + Assert.NotNull(runtimeSupportDllEntry); + } + } + + private string FindSolutionRoot() + { + string currentDirectory = Directory.GetCurrentDirectory(); + while (currentDirectory != null) + { + string[] solutionFiles = Directory.GetFiles(currentDirectory, "*.sln"); + if (solutionFiles.Length > 0) + { + return currentDirectory; + } + currentDirectory = Directory.GetParent(currentDirectory)?.FullName; + } + throw new Exception("Could not find the solution root directory."); + } + + +}