|
2 | 2 | using System.Diagnostics;
|
3 | 3 | using System.IO;
|
4 | 4 | using System.IO.Compression;
|
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
5 | 7 | using Xunit;
|
| 8 | +using Xunit.Abstractions; |
6 | 9 |
|
7 | 10 | namespace Amazon.Lambda.TestTool.UnitTests;
|
8 | 11 |
|
9 | 12 | public class PackagingTests
|
10 | 13 | {
|
| 14 | + private readonly ITestOutputHelper _output; |
| 15 | + private static readonly string[] ExpectedFrameworks = new[] |
| 16 | + { |
| 17 | + "net5.0", |
| 18 | + "net6.0", |
| 19 | + "net8.0", |
| 20 | + "netstandard2.0" |
| 21 | + }; |
| 22 | + |
| 23 | + public PackagingTests(ITestOutputHelper output) |
| 24 | + { |
| 25 | + _output = output; |
| 26 | + } |
| 27 | + |
11 | 28 | [Fact]
|
12 | 29 | public void VerifyPackageContentsHasRuntimeSupport()
|
13 | 30 | {
|
14 |
| - string projectPath = Path.Combine(FindSolutionRoot(), "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj"); |
| 31 | + string solutionRoot = FindSolutionRoot(); |
| 32 | + string runtimeSupportPath = Path.Combine(solutionRoot, "Libraries", "src", "Amazon.Lambda.RuntimeSupport", "Amazon.Lambda.RuntimeSupport.csproj"); |
| 33 | + string projectPath = Path.Combine(solutionRoot, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj"); |
| 34 | + |
| 35 | + // Build RuntimeSupport first |
| 36 | + _output.WriteLine("Building RuntimeSupport..."); |
| 37 | + var buildProcess = new Process |
| 38 | + { |
| 39 | + StartInfo = new ProcessStartInfo |
| 40 | + { |
| 41 | + FileName = "dotnet", |
| 42 | + Arguments = $"build {runtimeSupportPath} -c Release", |
| 43 | + RedirectStandardOutput = true, |
| 44 | + RedirectStandardError = true, |
| 45 | + UseShellExecute = false, |
| 46 | + CreateNoWindow = true, |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + buildProcess.Start(); |
| 51 | + string buildOutput = buildProcess.StandardOutput.ReadToEnd(); |
| 52 | + string buildError = buildProcess.StandardError.ReadToEnd(); |
| 53 | + buildProcess.WaitForExit(); |
| 54 | + |
| 55 | + _output.WriteLine("Build Output:"); |
| 56 | + _output.WriteLine(buildOutput); |
| 57 | + if (!string.IsNullOrEmpty(buildError)) |
| 58 | + { |
| 59 | + _output.WriteLine("Build Errors:"); |
| 60 | + _output.WriteLine(buildError); |
| 61 | + } |
| 62 | + |
| 63 | + Assert.Equal(0, buildProcess.ExitCode); |
15 | 64 |
|
16 |
| - var process = new Process |
| 65 | + // Now pack the test tool |
| 66 | + _output.WriteLine("\nPacking TestTool..."); |
| 67 | + var packProcess = new Process |
17 | 68 | {
|
18 | 69 | StartInfo = new ProcessStartInfo
|
19 | 70 | {
|
20 | 71 | FileName = "dotnet",
|
21 | 72 | Arguments = $"pack {projectPath} -c Release",
|
22 | 73 | RedirectStandardOutput = true,
|
| 74 | + RedirectStandardError = true, |
23 | 75 | UseShellExecute = false,
|
24 | 76 | CreateNoWindow = true,
|
25 | 77 | }
|
26 | 78 | };
|
27 | 79 |
|
28 |
| - process.Start(); |
29 |
| - string output = process.StandardOutput.ReadToEnd(); |
30 |
| - process.WaitForExit(); |
| 80 | + packProcess.Start(); |
| 81 | + string packOutput = packProcess.StandardOutput.ReadToEnd(); |
| 82 | + string packError = packProcess.StandardError.ReadToEnd(); |
| 83 | + packProcess.WaitForExit(); |
31 | 84 |
|
32 |
| - Assert.Equal(0, process.ExitCode); |
| 85 | + _output.WriteLine("Pack Output:"); |
| 86 | + _output.WriteLine(packOutput); |
| 87 | + if (!string.IsNullOrEmpty(packError)) |
| 88 | + { |
| 89 | + _output.WriteLine("Pack Errors:"); |
| 90 | + _output.WriteLine(packError); |
| 91 | + } |
| 92 | + |
| 93 | + Assert.Equal(0, packProcess.ExitCode); |
| 94 | + |
| 95 | + string packageDir = Path.Combine(Path.GetDirectoryName(projectPath), "bin", "Release"); |
| 96 | + _output.WriteLine($"Looking for package in: {packageDir}"); |
| 97 | + |
| 98 | + var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories); |
| 99 | + Assert.True(packageFiles.Length > 0, $"No .nupkg files found in {packageDir}"); |
33 | 100 |
|
34 |
| - string packagePath = Directory.GetFiles(Path.GetDirectoryName(projectPath), "*.nupkg", SearchOption.AllDirectories)[0]; |
| 101 | + // Rest of the verification code remains the same... |
| 102 | + string packagePath = packageFiles[0]; |
| 103 | + _output.WriteLine($"Found package: {packagePath}"); |
35 | 104 |
|
36 | 105 | using (var archive = ZipFile.OpenRead(packagePath))
|
37 | 106 | {
|
38 |
| - var runtimeSupportDllEntry = archive.GetEntry("content/Amazon.Lambda.RuntimeSupport.dll"); |
39 |
| - Assert.NotNull(runtimeSupportDllEntry); |
| 107 | + var missingFiles = new List<string>(); |
| 108 | + |
| 109 | + foreach (var framework in ExpectedFrameworks) |
| 110 | + { |
| 111 | + var expectedPath = $"content/{framework}/Amazon.Lambda.RuntimeSupport.dll"; |
| 112 | + var entry = archive.GetEntry(expectedPath); |
| 113 | + |
| 114 | + if (entry == null) |
| 115 | + { |
| 116 | + missingFiles.Add(expectedPath); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + if (missingFiles.Any()) |
| 121 | + { |
| 122 | + Assert.Fail($"The following RuntimeSupport DLLs are missing from the package:\n" + |
| 123 | + string.Join("\n", missingFiles)); |
| 124 | + } |
| 125 | + |
| 126 | + var actualFrameworkDlls = archive.Entries |
| 127 | + .Where(e => e.FullName.Contains("Amazon.Lambda.RuntimeSupport.dll")) |
| 128 | + .Select(e => e.FullName) |
| 129 | + .ToList(); |
| 130 | + |
| 131 | + _output.WriteLine("\nFound DLLs in package:"); |
| 132 | + foreach (var dll in actualFrameworkDlls) |
| 133 | + { |
| 134 | + _output.WriteLine(dll); |
| 135 | + } |
40 | 136 | }
|
41 | 137 | }
|
42 | 138 |
|
| 139 | + |
43 | 140 | private string FindSolutionRoot()
|
44 | 141 | {
|
45 | 142 | string currentDirectory = Directory.GetCurrentDirectory();
|
46 | 143 | while (currentDirectory != null)
|
47 | 144 | {
|
48 |
| - string[] solutionFiles = Directory.GetFiles(currentDirectory, "*.sln*"); |
49 |
| - if (solutionFiles.Length > 0) |
| 145 | + // Look for the aws-lambda-dotnet directory specifically |
| 146 | + if (Path.GetFileName(currentDirectory) == "aws-lambda-dotnet") |
50 | 147 | {
|
51 | 148 | return currentDirectory;
|
52 | 149 | }
|
53 | 150 | currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
|
54 | 151 | }
|
55 |
| - throw new Exception("Could not find the solution root directory."); |
| 152 | + throw new Exception("Could not find the aws-lambda-dotnet root directory."); |
56 | 153 | }
|
57 |
| - |
58 |
| - |
59 | 154 | }
|
0 commit comments