2
2
import shutil
3
3
import tempfile
4
4
import json
5
+ from parameterized import parameterized
5
6
6
7
try :
7
8
import pathlib
@@ -25,21 +26,19 @@ def setUp(self):
25
26
self .artifacts_dir = tempfile .mkdtemp ()
26
27
self .scratch_dir = tempfile .mkdtemp ()
27
28
self .builder = LambdaBuilder (language = "dotnet" , dependency_manager = "cli-package" , application_framework = None )
28
- self .runtime = "dotnet6"
29
29
30
30
def tearDown (self ):
31
31
shutil .rmtree (self .artifacts_dir )
32
32
shutil .rmtree (self .scratch_dir )
33
33
34
- def verify_architecture (self , deps_file_name , expected_architecture , version = None ):
34
+ def verify_architecture (self , deps_file_name , expected_architecture , version ):
35
35
deps_file = pathlib .Path (self .artifacts_dir , deps_file_name )
36
36
37
37
if not deps_file .exists ():
38
38
self .fail ("Failed verifying architecture, {} file not found" .format (deps_file_name ))
39
39
40
40
with open (str (deps_file )) as f :
41
41
deps_json = json .loads (f .read ())
42
- version = version or self .runtime [- 3 :]
43
42
target_name = ".NETCoreApp,Version=v{}/{}" .format (version , expected_architecture )
44
43
target = deps_json .get ("runtimeTarget" ).get ("name" )
45
44
@@ -50,19 +49,24 @@ def verify_execute_permissions(self, entrypoint_file_name):
50
49
self .assertTrue (os .access (entrypoint_file_path , os .X_OK ))
51
50
52
51
53
- class TestDotnet6 (TestDotnetBase ):
52
+ class TestDotnet (TestDotnetBase ):
54
53
"""
55
- Tests for dotnet 6
54
+ Tests for dotnet
56
55
"""
57
56
58
57
def setUp (self ):
59
- super (TestDotnet6 , self ).setUp ()
60
- self .runtime = "dotnet6"
58
+ super (TestDotnet , self ).setUp ()
61
59
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 )
64
68
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 )
66
70
67
71
expected_files = {
68
72
"Amazon.Lambda.Core.dll" ,
@@ -77,14 +81,18 @@ def test_with_defaults_file(self):
77
81
output_files = set (os .listdir (self .artifacts_dir ))
78
82
79
83
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 )
81
85
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 )
84
94
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 )
88
96
89
97
expected_files = {
90
98
"Amazon.Lambda.Core.dll" ,
@@ -99,14 +107,18 @@ def test_with_defaults_file_x86(self):
99
107
output_files = set (os .listdir (self .artifacts_dir ))
100
108
101
109
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 )
103
111
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 )
106
120
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 )
110
122
111
123
expected_files = {
112
124
"Amazon.Lambda.Core.dll" ,
@@ -121,14 +133,18 @@ def test_with_defaults_file_arm64(self):
121
133
output_files = set (os .listdir (self .artifacts_dir ))
122
134
123
135
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 )
125
137
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 )
128
146
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 )
132
148
133
149
expected_files = {
134
150
"Amazon.Lambda.Core.dll" ,
@@ -144,7 +160,7 @@ def test_with_custom_runtime(self):
144
160
output_files = set (os .listdir (self .artifacts_dir ))
145
161
146
162
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 )
148
164
# Execute permissions are required for custom runtimes which bootstrap themselves, otherwise `sam local invoke`
149
165
# won't have permission to run the file
150
166
self .verify_execute_permissions ("bootstrap" )
0 commit comments