Skip to content

Commit

Permalink
add packaging of runtime
Browse files Browse the repository at this point in the history
fix test

Generate all runtime support dlls in content folder
  • Loading branch information
gcbeattyAWS committed Jan 14, 2025
1 parent f8577af commit 13a74ae
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Description>A tool to help debug and test your .NET AWS Lambda functions locally.</Description>
<Description>A tool to help debug and test your .NET AWS Lambda functions locally.</Description>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Product>AWS .NET Lambda Test Tool</Product>
<Copyright>Apache 2</Copyright>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<PackageId>Amazon.Lambda.TestTool</PackageId>
Expand All @@ -23,8 +22,24 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="wwwroot\**" />
<EmbeddedResource Include="Resources\**" />
<ProjectReference Include="..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\Amazon.Lambda.RuntimeSupport.csproj" />
</ItemGroup>

<ItemGroup>
<RuntimeSupportFramework Include="net5.0;net6.0;net8.0;netstandard2.0" />
</ItemGroup>

</Project>
<Target Name="ListRuntimeSupportDlls" BeforeTargets="PrepareForBuild">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)..\..\..\..\Libraries\src\Amazon.Lambda.RuntimeSupport\bin\$(Configuration)\%(RuntimeSupportFramework.Identity)\Amazon.Lambda.RuntimeSupport.dll">
<Pack>true</Pack>
<PackagePath>content\%(RuntimeSupportFramework.Identity)</PackagePath>
</Content>
</ItemGroup>
</Target>

<ItemGroup>
<EmbeddedResource Include="wwwroot\**" />
<EmbeddedResource Include="Resources\**" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj", "{129F6132-C0B3-6F05-B947-6FC288B0E9D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{129F6132-C0B3-6F05-B947-6FC288B0E9D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DFCCF963-C635-4341-B013-7CCA0D77559C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

namespace Amazon.Lambda.TestTool.UnitTests;

public class PackagingTests
{
private readonly ITestOutputHelper _output;
private static readonly string[] ExpectedFrameworks = new[]
{
"net5.0",
"net6.0",
"net8.0",
"netstandard2.0"
};

public PackagingTests(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public void VerifyPackageContentsHasRuntimeSupport()
{
string solutionRoot = FindSolutionRoot();
string runtimeSupportPath = Path.Combine(solutionRoot, "Libraries", "src", "Amazon.Lambda.RuntimeSupport", "Amazon.Lambda.RuntimeSupport.csproj");
string projectPath = Path.Combine(solutionRoot, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj");

// Build RuntimeSupport first
_output.WriteLine("Building RuntimeSupport...");
var buildProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"build {runtimeSupportPath} -c Release",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};

buildProcess.Start();
string buildOutput = buildProcess.StandardOutput.ReadToEnd();
string buildError = buildProcess.StandardError.ReadToEnd();
buildProcess.WaitForExit();

_output.WriteLine("Build Output:");
_output.WriteLine(buildOutput);
if (!string.IsNullOrEmpty(buildError))
{
_output.WriteLine("Build Errors:");
_output.WriteLine(buildError);
}

Assert.Equal(0, buildProcess.ExitCode);

// Now pack the test tool
_output.WriteLine("\nPacking TestTool...");
var packProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"pack {projectPath} -c Release",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};

packProcess.Start();
string packOutput = packProcess.StandardOutput.ReadToEnd();
string packError = packProcess.StandardError.ReadToEnd();
packProcess.WaitForExit();

_output.WriteLine("Pack Output:");
_output.WriteLine(packOutput);
if (!string.IsNullOrEmpty(packError))
{
_output.WriteLine("Pack Errors:");
_output.WriteLine(packError);
}

Assert.Equal(0, packProcess.ExitCode);

string 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}");

// Rest of the verification code remains the same...
string packagePath = packageFiles[0];
_output.WriteLine($"Found package: {packagePath}");

using (var archive = ZipFile.OpenRead(packagePath))
{
var missingFiles = new List<string>();

foreach (var framework in ExpectedFrameworks)
{
var expectedPath = $"content/{framework}/Amazon.Lambda.RuntimeSupport.dll";
var entry = archive.GetEntry(expectedPath);

if (entry == null)
{
missingFiles.Add(expectedPath);
}
}

if (missingFiles.Any())
{
Assert.Fail($"The following RuntimeSupport DLLs are missing from the package:\n" +
string.Join("\n", missingFiles));
}

var actualFrameworkDlls = archive.Entries
.Where(e => e.FullName.Contains("Amazon.Lambda.RuntimeSupport.dll"))
.Select(e => e.FullName)
.ToList();

_output.WriteLine("\nFound DLLs in package:");
foreach (var dll in actualFrameworkDlls)
{
_output.WriteLine(dll);
}
}
}


private string FindSolutionRoot()
{
string currentDirectory = Directory.GetCurrentDirectory();
while (currentDirectory != null)
{
// Look for the aws-lambda-dotnet directory specifically
if (Path.GetFileName(currentDirectory) == "aws-lambda-dotnet")
{
return currentDirectory;
}
currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
}
throw new Exception("Could not find the aws-lambda-dotnet root directory.");
}
}

0 comments on commit 13a74ae

Please sign in to comment.