-
Notifications
You must be signed in to change notification settings - Fork 491
Add Amazon.Lambda.RuntimeSupport dll to the output nuget package #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
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 readonly string[] _expectedFrameworks; | ||
|
||
public PackagingTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
_expectedFrameworks = GetRuntimeSupportTargetFrameworks() | ||
.Split([';'], StringSplitOptions.RemoveEmptyEntries) | ||
.Where(f => f != "netstandard2.0") | ||
.ToArray(); | ||
} | ||
|
||
private string GetRuntimeSupportTargetFrameworks() | ||
{ | ||
var solutionRoot = FindSolutionRoot(); | ||
var runtimeSupportPath = Path.Combine(solutionRoot, "Libraries", "src", "Amazon.Lambda.RuntimeSupport", "Amazon.Lambda.RuntimeSupport.csproj"); | ||
|
||
var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "dotnet", | ||
Arguments = $"msbuild {runtimeSupportPath} --getProperty:TargetFrameworks", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
process.Start(); | ||
var output = process.StandardOutput.ReadToEnd(); | ||
var error = process.StandardError.ReadToEnd(); | ||
process.WaitForExit(); | ||
|
||
if (process.ExitCode != 0) | ||
{ | ||
throw new Exception($"Failed to get TargetFrameworks: {error}"); | ||
} | ||
|
||
return output.Trim(); | ||
} | ||
|
||
[Fact] | ||
public void VerifyPackageContentsHasRuntimeSupport() | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var solutionRoot = FindSolutionRoot(); | ||
var projectPath = Path.Combine(solutionRoot, "Tools", "LambdaTestTool-v2", "src", "Amazon.Lambda.TestTool", "Amazon.Lambda.TestTool.csproj"); | ||
|
||
_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); | ||
|
||
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() | ||
{ | ||
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."); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we could skip
netstandard2.0
because it doesn't make any sense in this context. Thenetstandard2.0
target is for class libraries not executables.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive updated the logic in the csproj and the unit test to dynamically get the targetframeworks and also skip netstandard2.0