Skip to content

Commit 947400a

Browse files
committed
update test
1 parent 561fc09 commit 947400a

File tree

1 file changed

+66
-42
lines changed

1 file changed

+66
-42
lines changed

Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,54 @@ namespace Amazon.Lambda.TestTool.UnitTests;
1212
public class PackagingTests
1313
{
1414
private readonly ITestOutputHelper _output;
15-
private static readonly string[] ExpectedFrameworks = new[]
16-
{
17-
"net6.0",
18-
"net8.0",
19-
"net9.0",
20-
"netstandard2.0"
21-
};
15+
private readonly string[] _expectedFrameworks;
2216

2317
public PackagingTests(ITestOutputHelper output)
2418
{
2519
_output = output;
20+
_expectedFrameworks = GetRuntimeSupportTargetFrameworks()
21+
.Split([';'], StringSplitOptions.RemoveEmptyEntries)
22+
.Where(f => f != "netstandard2.0")
23+
.ToArray();
24+
}
25+
26+
private string GetRuntimeSupportTargetFrameworks()
27+
{
28+
var solutionRoot = FindSolutionRoot();
29+
var runtimeSupportPath = Path.Combine(solutionRoot, "Libraries", "src", "Amazon.Lambda.RuntimeSupport", "Amazon.Lambda.RuntimeSupport.csproj");
30+
31+
var process = new Process
32+
{
33+
StartInfo = new ProcessStartInfo
34+
{
35+
FileName = "dotnet",
36+
Arguments = $"msbuild {runtimeSupportPath} --getProperty:TargetFrameworks",
37+
RedirectStandardOutput = true,
38+
RedirectStandardError = true,
39+
UseShellExecute = false,
40+
CreateNoWindow = true,
41+
}
42+
};
43+
44+
process.Start();
45+
var output = process.StandardOutput.ReadToEnd();
46+
var error = process.StandardError.ReadToEnd();
47+
process.WaitForExit();
48+
49+
if (process.ExitCode != 0)
50+
{
51+
throw new Exception($"Failed to get TargetFrameworks: {error}");
52+
}
53+
54+
return output.Trim();
2655
}
2756

2857
[Fact]
2958
public void VerifyPackageContentsHasRuntimeSupport()
3059
{
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");
60+
var solutionRoot = FindSolutionRoot();
61+
var projectPath = Path.Combine(solutionRoot, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj");
3462

35-
// Now pack the test tool
3663
_output.WriteLine("\nPacking TestTool...");
3764
var packProcess = new Process
3865
{
@@ -62,50 +89,47 @@ public void VerifyPackageContentsHasRuntimeSupport()
6289

6390
Assert.Equal(0, packProcess.ExitCode);
6491

65-
string packageDir = Path.Combine(Path.GetDirectoryName(projectPath), "bin", "Release");
92+
var packageDir = Path.Combine(Path.GetDirectoryName(projectPath), "bin", "Release");
6693
_output.WriteLine($"Looking for package in: {packageDir}");
6794

6895
var packageFiles = Directory.GetFiles(packageDir, "*.nupkg", SearchOption.AllDirectories);
6996
Assert.True(packageFiles.Length > 0, $"No .nupkg files found in {packageDir}");
7097

71-
string packagePath = packageFiles[0];
98+
var packagePath = packageFiles[0];
7299
_output.WriteLine($"Found package: {packagePath}");
73100

74-
using (var archive = ZipFile.OpenRead(packagePath))
101+
using var archive = ZipFile.OpenRead(packagePath);
102+
// Verify each framework has its required files
103+
foreach (var framework in _expectedFrameworks)
75104
{
76-
// Verify each framework has its required files
77-
foreach (var framework in ExpectedFrameworks)
105+
_output.WriteLine($"\nChecking framework: {framework}");
106+
107+
// Get all files for this framework
108+
var frameworkFiles = archive.Entries
109+
.Where(e => e.FullName.StartsWith($"content/Amazon.Lambda.RuntimeSupport/{framework}/"))
110+
.Select(e => e.FullName)
111+
.ToList();
112+
113+
// Verify essential files exist
114+
var essentialFiles = new[]
78115
{
79-
_output.WriteLine($"\nChecking framework: {framework}");
80-
81-
// Get all files for this framework
82-
var frameworkFiles = archive.Entries
83-
.Where(e => e.FullName.StartsWith($"content/{framework}/"))
84-
.Select(e => e.FullName)
85-
.ToList();
86-
87-
// Verify essential files exist
88-
var essentialFiles = new[]
89-
{
90-
$"content/{framework}/Amazon.Lambda.RuntimeSupport.dll",
91-
$"content/{framework}/Amazon.Lambda.RuntimeSupport.deps.json",
92-
$"content/{framework}/bootstrap.sh",
93-
$"content/{framework}/bootstrap-al2023.sh"
116+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.Core.dll",
117+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.dll",
118+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.deps.json"
94119
};
95120

96-
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Contains(f)).ToList();
121+
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Contains(f)).ToList();
97122

98-
if (missingFiles.Any())
99-
{
100-
Assert.Fail($"The following essential files are missing for {framework}:\n" +
101-
string.Join("\n", missingFiles));
102-
}
123+
if (missingFiles.Any())
124+
{
125+
Assert.Fail($"The following essential files are missing for {framework}:\n" +
126+
string.Join("\n", missingFiles));
127+
}
103128

104-
_output.WriteLine($"Files found for {framework}:");
105-
foreach (var file in frameworkFiles)
106-
{
107-
_output.WriteLine($" {file}");
108-
}
129+
_output.WriteLine($"Files found for {framework}:");
130+
foreach (var file in frameworkFiles)
131+
{
132+
_output.WriteLine($" {file}");
109133
}
110134
}
111135
}

0 commit comments

Comments
 (0)