|
| 1 | +using System; |
| 2 | +using System.Diagnostics; |
| 3 | +using System.IO; |
| 4 | +using System.IO.Compression; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace Amazon.Lambda.TestTool.UnitTests; |
| 8 | + |
| 9 | +public class PackagingTests |
| 10 | +{ |
| 11 | + [Fact] |
| 12 | + public void VerifyPackageContentsHasRuntimeSupport() |
| 13 | + { |
| 14 | + string projectPath = Path.Combine(FindSolutionRoot(), "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj"); |
| 15 | + |
| 16 | + var process = new Process |
| 17 | + { |
| 18 | + StartInfo = new ProcessStartInfo |
| 19 | + { |
| 20 | + FileName = "dotnet", |
| 21 | + Arguments = $"pack {projectPath} -c Release", |
| 22 | + RedirectStandardOutput = true, |
| 23 | + UseShellExecute = false, |
| 24 | + CreateNoWindow = true, |
| 25 | + } |
| 26 | + }; |
| 27 | + |
| 28 | + process.Start(); |
| 29 | + string output = process.StandardOutput.ReadToEnd(); |
| 30 | + process.WaitForExit(); |
| 31 | + |
| 32 | + Assert.Equal(0, process.ExitCode); |
| 33 | + |
| 34 | + string packagePath = Directory.GetFiles(Path.GetDirectoryName(projectPath), "*.nupkg", SearchOption.AllDirectories)[0]; |
| 35 | + |
| 36 | + using (var archive = ZipFile.OpenRead(packagePath)) |
| 37 | + { |
| 38 | + var runtimeSupportDllEntry = archive.GetEntry("content/Amazon.Lambda.RuntimeSupport.dll"); |
| 39 | + Assert.NotNull(runtimeSupportDllEntry); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + private string FindSolutionRoot() |
| 44 | + { |
| 45 | + string currentDirectory = Directory.GetCurrentDirectory(); |
| 46 | + while (currentDirectory != null) |
| 47 | + { |
| 48 | + string[] solutionFiles = Directory.GetFiles(currentDirectory, "*.sln"); |
| 49 | + if (solutionFiles.Length > 0) |
| 50 | + { |
| 51 | + return currentDirectory; |
| 52 | + } |
| 53 | + currentDirectory = Directory.GetParent(currentDirectory)?.FullName; |
| 54 | + } |
| 55 | + throw new Exception("Could not find the solution root directory."); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | +} |
0 commit comments