Skip to content

Commit 13a74ae

Browse files
committed
add packaging of runtime
fix test Generate all runtime support dlls in content folder
1 parent f8577af commit 13a74ae

File tree

3 files changed

+200
-7
lines changed

3 files changed

+200
-7
lines changed
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
32
<PropertyGroup>
4-
<Description>A tool to help debug and test your .NET AWS Lambda functions locally.</Description>
3+
<Description>A tool to help debug and test your .NET AWS Lambda functions locally.</Description>
54
<TargetFramework>net8.0</TargetFramework>
65
<Nullable>enable</Nullable>
76
<ImplicitUsings>enable</ImplicitUsings>
87
<Product>AWS .NET Lambda Test Tool</Product>
98
<Copyright>Apache 2</Copyright>
109
<PackageTags>AWS;Amazon;Lambda</PackageTags>
11-
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
10+
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
1211
<IsPackable>true</IsPackable>
1312
<PackAsTool>true</PackAsTool>
1413
<PackageId>Amazon.Lambda.TestTool</PackageId>
@@ -23,8 +22,24 @@
2322
</ItemGroup>
2423

2524
<ItemGroup>
26-
<EmbeddedResource Include="wwwroot\**" />
27-
<EmbeddedResource Include="Resources\**" />
25+
<ProjectReference Include="..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<RuntimeSupportFramework Include="net5.0;net6.0;net8.0;netstandard2.0" />
2830
</ItemGroup>
2931

30-
</Project>
32+
<Target Name="ListRuntimeSupportDlls" BeforeTargets="PrepareForBuild">
33+
<ItemGroup>
34+
<Content Include="$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\bin\$(Configuration)\%(RuntimeSupportFramework.Identity)\Amazon.Lambda.RuntimeSupport.dll">
35+
<Pack>true</Pack>
36+
<PackagePath>content\%(RuntimeSupportFramework.Identity)</PackagePath>
37+
</Content>
38+
</ItemGroup>
39+
</Target>
40+
41+
<ItemGroup>
42+
<EmbeddedResource Include="wwwroot\**" />
43+
<EmbeddedResource Include="Resources\**" />
44+
</ItemGroup>
45+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj", "{129F6132-C0B3-6F05-B947-6FC288B0E9D9}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {DFCCF963-C635-4341-B013-7CCA0D77559C}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.IO.Compression;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Amazon.Lambda.TestTool.UnitTests;
11+
12+
public class PackagingTests
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+
28+
[Fact]
29+
public void VerifyPackageContentsHasRuntimeSupport()
30+
{
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);
64+
65+
// Now pack the test tool
66+
_output.WriteLine("\nPacking TestTool...");
67+
var packProcess = new Process
68+
{
69+
StartInfo = new ProcessStartInfo
70+
{
71+
FileName = "dotnet",
72+
Arguments = $"pack {projectPath} -c Release",
73+
RedirectStandardOutput = true,
74+
RedirectStandardError = true,
75+
UseShellExecute = false,
76+
CreateNoWindow = true,
77+
}
78+
};
79+
80+
packProcess.Start();
81+
string packOutput = packProcess.StandardOutput.ReadToEnd();
82+
string packError = packProcess.StandardError.ReadToEnd();
83+
packProcess.WaitForExit();
84+
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}");
100+
101+
// Rest of the verification code remains the same...
102+
string packagePath = packageFiles[0];
103+
_output.WriteLine($"Found package: {packagePath}");
104+
105+
using (var archive = ZipFile.OpenRead(packagePath))
106+
{
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+
}
136+
}
137+
}
138+
139+
140+
private string FindSolutionRoot()
141+
{
142+
string currentDirectory = Directory.GetCurrentDirectory();
143+
while (currentDirectory != null)
144+
{
145+
// Look for the aws-lambda-dotnet directory specifically
146+
if (Path.GetFileName(currentDirectory) == "aws-lambda-dotnet")
147+
{
148+
return currentDirectory;
149+
}
150+
currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
151+
}
152+
throw new Exception("Could not find the aws-lambda-dotnet root directory.");
153+
}
154+
}

0 commit comments

Comments
 (0)