22import shutil
33import tempfile
44import json
5+ from parameterized import parameterized
56
67try :
78 import pathlib
@@ -25,21 +26,19 @@ def setUp(self):
2526 self .artifacts_dir = tempfile .mkdtemp ()
2627 self .scratch_dir = tempfile .mkdtemp ()
2728 self .builder = LambdaBuilder (language = "dotnet" , dependency_manager = "cli-package" , application_framework = None )
28- self .runtime = "dotnet6"
2929
3030 def tearDown (self ):
3131 shutil .rmtree (self .artifacts_dir )
3232 shutil .rmtree (self .scratch_dir )
3333
34- def verify_architecture (self , deps_file_name , expected_architecture , version = None ):
34+ def verify_architecture (self , deps_file_name , expected_architecture , version ):
3535 deps_file = pathlib .Path (self .artifacts_dir , deps_file_name )
3636
3737 if not deps_file .exists ():
3838 self .fail ("Failed verifying architecture, {} file not found" .format (deps_file_name ))
3939
4040 with open (str (deps_file )) as f :
4141 deps_json = json .loads (f .read ())
42- version = version or self .runtime [- 3 :]
4342 target_name = ".NETCoreApp,Version=v{}/{}" .format (version , expected_architecture )
4443 target = deps_json .get ("runtimeTarget" ).get ("name" )
4544
@@ -50,19 +49,24 @@ def verify_execute_permissions(self, entrypoint_file_name):
5049 self .assertTrue (os .access (entrypoint_file_path , os .X_OK ))
5150
5251
53- class TestDotnet6 (TestDotnetBase ):
52+ class TestDotnet (TestDotnetBase ):
5453 """
55- Tests for dotnet 6
54+ Tests for dotnet
5655 """
5756
5857 def setUp (self ):
59- super (TestDotnet6 , self ).setUp ()
60- self .runtime = "dotnet6"
58+ super (TestDotnet , self ).setUp ()
6159
62- def test_with_defaults_file (self ):
63- source_dir = os .path .join (self .TEST_DATA_FOLDER , "WithDefaultsFile6" )
60+ @parameterized .expand (
61+ [
62+ ("dotnet6" , "6.0" , "WithDefaultsFile6" ),
63+ ("dotnet8" , "8.0" , "WithDefaultsFile8" ),
64+ ]
65+ )
66+ def test_with_defaults_file (self , runtime , version , test_project ):
67+ source_dir = os .path .join (self .TEST_DATA_FOLDER , test_project )
6468
65- self .builder .build (source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime = self . runtime )
69+ self .builder .build (source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime )
6670
6771 expected_files = {
6872 "Amazon.Lambda.Core.dll" ,
@@ -77,14 +81,18 @@ def test_with_defaults_file(self):
7781 output_files = set (os .listdir (self .artifacts_dir ))
7882
7983 self .assertEqual (expected_files , output_files )
80- self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-x64" , version = "6.0" )
84+ self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-x64" , version )
8185
82- def test_with_defaults_file_x86 (self ):
83- source_dir = os .path .join (self .TEST_DATA_FOLDER , "WithDefaultsFile6" )
86+ @parameterized .expand (
87+ [
88+ ("dotnet6" , "6.0" , "WithDefaultsFile6" ),
89+ ("dotnet8" , "8.0" , "WithDefaultsFile8" ),
90+ ]
91+ )
92+ def test_with_defaults_file_x86 (self , runtime , version , test_project ):
93+ source_dir = os .path .join (self .TEST_DATA_FOLDER , test_project )
8494
85- self .builder .build (
86- source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime = self .runtime , architecture = X86_64
87- )
95+ self .builder .build (source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime , architecture = X86_64 )
8896
8997 expected_files = {
9098 "Amazon.Lambda.Core.dll" ,
@@ -99,14 +107,18 @@ def test_with_defaults_file_x86(self):
99107 output_files = set (os .listdir (self .artifacts_dir ))
100108
101109 self .assertEqual (expected_files , output_files )
102- self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-x64" , version = "6.0" )
110+ self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-x64" , version )
103111
104- def test_with_defaults_file_arm64 (self ):
105- source_dir = os .path .join (self .TEST_DATA_FOLDER , "WithDefaultsFile6" )
112+ @parameterized .expand (
113+ [
114+ ("dotnet6" , "6.0" , "WithDefaultsFile6" ),
115+ ("dotnet8" , "8.0" , "WithDefaultsFile8" ),
116+ ]
117+ )
118+ def test_with_defaults_file_arm64 (self , runtime , version , test_project ):
119+ source_dir = os .path .join (self .TEST_DATA_FOLDER , test_project )
106120
107- self .builder .build (
108- source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime = self .runtime , architecture = ARM64
109- )
121+ self .builder .build (source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime , architecture = ARM64 )
110122
111123 expected_files = {
112124 "Amazon.Lambda.Core.dll" ,
@@ -121,14 +133,18 @@ def test_with_defaults_file_arm64(self):
121133 output_files = set (os .listdir (self .artifacts_dir ))
122134
123135 self .assertEqual (expected_files , output_files )
124- self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-arm64" , version = "6.0" )
136+ self .verify_architecture ("WithDefaultsFile.deps.json" , "linux-arm64" , version )
125137
126- def test_with_custom_runtime (self ):
127- source_dir = os .path .join (self .TEST_DATA_FOLDER , "CustomRuntime6" )
138+ @parameterized .expand (
139+ [
140+ ("dotnet6" , "6.0" , "CustomRuntime6" ),
141+ ("dotnet8" , "8.0" , "CustomRuntime8" ),
142+ ]
143+ )
144+ def test_with_custom_runtime (self , runtime , version , test_project ):
145+ source_dir = os .path .join (self .TEST_DATA_FOLDER , test_project )
128146
129- self .builder .build (
130- source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime = self .runtime , architecture = X86_64
131- )
147+ self .builder .build (source_dir , self .artifacts_dir , self .scratch_dir , source_dir , runtime , architecture = X86_64 )
132148
133149 expected_files = {
134150 "Amazon.Lambda.Core.dll" ,
@@ -144,7 +160,7 @@ def test_with_custom_runtime(self):
144160 output_files = set (os .listdir (self .artifacts_dir ))
145161
146162 self .assertEqual (expected_files , output_files )
147- self .verify_architecture ("bootstrap.deps.json" , "linux-x64" , version = "6.0" )
163+ self .verify_architecture ("bootstrap.deps.json" , "linux-x64" , version )
148164 # Execute permissions are required for custom runtimes which bootstrap themselves, otherwise `sam local invoke`
149165 # won't have permission to run the file
150166 self .verify_execute_permissions ("bootstrap" )
0 commit comments