@@ -12,27 +12,54 @@ namespace Amazon.Lambda.TestTool.UnitTests;
12
12
public class PackagingTests
13
13
{
14
14
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 ;
22
16
23
17
public PackagingTests ( ITestOutputHelper output )
24
18
{
25
19
_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 ( ) ;
26
55
}
27
56
28
57
[ Fact ]
29
58
public void VerifyPackageContentsHasRuntimeSupport ( )
30
59
{
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" ) ;
34
62
35
- // Now pack the test tool
36
63
_output . WriteLine ( "\n Packing TestTool..." ) ;
37
64
var packProcess = new Process
38
65
{
@@ -62,50 +89,47 @@ public void VerifyPackageContentsHasRuntimeSupport()
62
89
63
90
Assert . Equal ( 0 , packProcess . ExitCode ) ;
64
91
65
- string packageDir = Path . Combine ( Path . GetDirectoryName ( projectPath ) , "bin" , "Release" ) ;
92
+ var packageDir = Path . Combine ( Path . GetDirectoryName ( projectPath ) , "bin" , "Release" ) ;
66
93
_output . WriteLine ( $ "Looking for package in: { packageDir } ") ;
67
94
68
95
var packageFiles = Directory . GetFiles ( packageDir , "*.nupkg" , SearchOption . AllDirectories ) ;
69
96
Assert . True ( packageFiles . Length > 0 , $ "No .nupkg files found in { packageDir } ") ;
70
97
71
- string packagePath = packageFiles [ 0 ] ;
98
+ var packagePath = packageFiles [ 0 ] ;
72
99
_output . WriteLine ( $ "Found package: { packagePath } ") ;
73
100
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 )
75
104
{
76
- // Verify each framework has its required files
77
- foreach ( var framework in ExpectedFrameworks )
105
+ _output . WriteLine ( $ "\n Checking 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 [ ]
78
115
{
79
- _output . WriteLine ( $ "\n Checking 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"
94
119
} ;
95
120
96
- var missingFiles = essentialFiles . Where ( f => ! frameworkFiles . Contains ( f ) ) . ToList ( ) ;
121
+ var missingFiles = essentialFiles . Where ( f => ! frameworkFiles . Contains ( f ) ) . ToList ( ) ;
97
122
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
+ }
103
128
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 } ") ;
109
133
}
110
134
}
111
135
}
0 commit comments