-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathPackagingTests.cs
More file actions
191 lines (161 loc) · 7.26 KB
/
PackagingTests.cs
File metadata and controls
191 lines (161 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System.Diagnostics;
using System.IO.Compression;
using Amazon.Lambda.TestTool.UnitTests.Utilities;
using Xunit;
using Xunit.Abstractions;
namespace Amazon.Lambda.TestTool.UnitTests;
public class PackagingTests : IDisposable
{
private readonly ITestOutputHelper _output;
private readonly string _workingDirectory;
public PackagingTests(ITestOutputHelper output)
{
_output = output;
var solutionRoot = FindSolutionRoot();
_workingDirectory = DirectoryHelpers.GetTempTestAppDirectory(solutionRoot);
}
[Fact]
public void VerifyPackageContentsHasStaticAssets()
{
var projectPath = Path.Combine(_workingDirectory, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj");
_output.WriteLine("Packing TestTool...");
var packProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"pack -c Release --no-build --no-restore {projectPath}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
packProcess.Start();
string packOutput = packProcess.StandardOutput.ReadToEnd();
string packError = packProcess.StandardError.ReadToEnd();
packProcess.WaitForExit(int.MaxValue);
_output.WriteLine("Pack Output:");
_output.WriteLine(packOutput);
if (!string.IsNullOrEmpty(packError))
{
_output.WriteLine("Pack Errors:");
_output.WriteLine(packError);
}
Assert.Equal(0, packProcess.ExitCode);
var packageDir = Path.Combine(Path.GetDirectoryName(projectPath)!, "bin", "Release");
_output.WriteLine($"Looking for package in: {packageDir}");
var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories);
Assert.True(packageFiles.Length > 0, $"No .nupkg files found in {packageDir}");
var packagePath = packageFiles[0];
_output.WriteLine($"Found package: {packagePath}");
using var archive = ZipFile.OpenRead(packagePath);
// Get all files for this framework
var frameworkFiles = archive.Entries
.Where(e => e.FullName.StartsWith($"tools/net8.0/any/wwwroot"))
.Select(e => e.FullName)
.ToList();
// Verify essential files exist
var essentialFiles = new[]
{
$"tools/net8.0/any/wwwroot/bootstrap-icons/",
$"tools/net8.0/any/wwwroot/bootstrap/",
$"tools/net8.0/any/wwwroot/_content/BlazorMonaco/"
};
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Any(x => x.StartsWith(f))).ToList();
if (missingFiles.Any())
{
Assert.Fail($"The following static assets are missing:\n" +
string.Join("\n", missingFiles));
}
}
[Fact]
public void VerifyPackageContentsHasRuntimeSupport()
{
var projectPath = Path.Combine(_workingDirectory, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj");
var expectedFrameworks = new string[] { "net6.0", "net8.0", "net9.0", "net10.0" };
_output.WriteLine("Packing TestTool...");
var packProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"pack -c Release --no-build --no-restore {projectPath}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
packProcess.Start();
string packOutput = packProcess.StandardOutput.ReadToEnd();
string packError = packProcess.StandardError.ReadToEnd();
packProcess.WaitForExit(int.MaxValue);
_output.WriteLine("Pack Output:");
_output.WriteLine(packOutput);
if (!string.IsNullOrEmpty(packError))
{
_output.WriteLine("Pack Errors:");
_output.WriteLine(packError);
}
Assert.Equal(0, packProcess.ExitCode);
var packageDir = Path.Combine(Path.GetDirectoryName(projectPath)!, "bin", "Release");
_output.WriteLine($"Looking for package in: {packageDir}");
var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories);
Assert.True(packageFiles.Length > 0, $"No .nupkg files found in {packageDir}");
var packagePath = packageFiles[0];
_output.WriteLine($"Found package: {packagePath}");
using var archive = ZipFile.OpenRead(packagePath);
// Verify each framework has its required files
foreach (var framework in expectedFrameworks)
{
_output.WriteLine($"\nChecking framework: {framework}");
// Get all files for this framework
var frameworkFiles = archive.Entries
.Where(e => e.FullName.StartsWith($"content/Amazon.Lambda.RuntimeSupport/{framework}/"))
.Select(e => e.FullName)
.ToList();
// Verify essential files exist
var essentialFiles = new[]
{
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.Core.dll",
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.dll",
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.deps.json",
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.runtimeconfig.json"
};
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Contains(f)).ToList();
if (missingFiles.Any())
{
Assert.Fail($"The following essential files are missing for {framework}:\n" +
string.Join("\n", missingFiles));
}
_output.WriteLine($"Files found for {framework}:");
foreach (var file in frameworkFiles)
{
_output.WriteLine($" {file}");
}
}
}
private string FindSolutionRoot()
{
Console.WriteLine("Looking for solution root...");
string? currentDirectory = Directory.GetCurrentDirectory();
while (currentDirectory != null)
{
// Look for the "Tools" directory specifically and then go up one level to the root of the repository.
// The reason we do this is because the source directory "aws-lambda-dotnet" does not always exist in the CI.
// In CodeBuild, the contents of "aws-lambda-dotnet" get copied to a temp location,
// so the path does not contain the name "aws-lambda-dotnet".
if (Path.GetFileName(currentDirectory) == "Tools")
{
return Path.Combine(currentDirectory, "..");
}
currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
}
throw new Exception("Could not find the 'Tools' root directory.");
}
public void Dispose()
{
DirectoryHelpers.CleanUp(_workingDirectory);
}
}