1
1
from unittest import TestCase
2
2
from unittest .mock import patch
3
+ from parameterized import parameterized
3
4
import io
4
5
import logging
5
6
import os
@@ -43,9 +44,35 @@ def which(cmd, executable_search_paths):
43
44
proc = SubprocessCargoLambda (which = which , osutils = self .osutils )
44
45
self .subprocess_cargo_lambda = proc
45
46
47
+ @parameterized .expand (
48
+ [
49
+ ("provided.al2" , "x86_64" , "x86_64-unknown-linux-gnu.2.26" ),
50
+ ("provided.al2" , "arm64" , "aarch64-unknown-linux-gnu.2.26" ),
51
+ ]
52
+ )
53
+ def test_release_build_cargo_command_with_correct_targets (self , runtime , architecture , expected_target ):
54
+ cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
55
+ action = RustCargoLambdaBuildAction (
56
+ "source_dir" , {"cargo" : cargo }, None , self .subprocess_cargo_lambda , runtime , architecture
57
+ )
58
+ self .assertEqual (
59
+ action .build_command (),
60
+ ["path/to/cargo" , "lambda" , "build" , "--release" , "--target" , expected_target ],
61
+ )
62
+
63
+ def test_release_build_cargo_command_for_provided_al2023 (self ):
64
+ cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
65
+ action = RustCargoLambdaBuildAction (
66
+ "source_dir" , {"cargo" : cargo }, None , self .subprocess_cargo_lambda , "provided.al2023"
67
+ )
68
+ self .assertEqual (
69
+ action .build_command (),
70
+ ["path/to/cargo" , "lambda" , "build" , "--release" ],
71
+ )
72
+
46
73
def test_release_build_cargo_command_without_release_mode (self ):
47
74
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
48
- action = RustCargoLambdaBuildAction ("source_dir" , {"cargo" : cargo }, None , self .subprocess_cargo_lambda )
75
+ action = RustCargoLambdaBuildAction ("source_dir" , {"cargo" : cargo }, None , None , self .subprocess_cargo_lambda )
49
76
self .assertEqual (
50
77
action .build_command (),
51
78
["path/to/cargo" , "lambda" , "build" , "--release" ],
@@ -54,7 +81,7 @@ def test_release_build_cargo_command_without_release_mode(self):
54
81
def test_release_build_cargo_command (self ):
55
82
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
56
83
action = RustCargoLambdaBuildAction (
57
- "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda
84
+ "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , None , self .subprocess_cargo_lambda
58
85
)
59
86
self .assertEqual (
60
87
action .build_command (),
@@ -64,7 +91,7 @@ def test_release_build_cargo_command(self):
64
91
def test_release_build_cargo_command_with_target (self ):
65
92
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
66
93
action = RustCargoLambdaBuildAction (
67
- "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda , "arm64"
94
+ "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , None , self .subprocess_cargo_lambda , "arm64"
68
95
)
69
96
self .assertEqual (
70
97
action .build_command (),
@@ -74,7 +101,7 @@ def test_release_build_cargo_command_with_target(self):
74
101
def test_debug_build_cargo_command (self ):
75
102
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
76
103
action = RustCargoLambdaBuildAction (
77
- "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , self .subprocess_cargo_lambda
104
+ "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , None , self .subprocess_cargo_lambda
78
105
)
79
106
self .assertEqual (
80
107
action .build_command (),
@@ -84,7 +111,7 @@ def test_debug_build_cargo_command(self):
84
111
def test_debug_build_cargo_command_with_architecture (self ):
85
112
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
86
113
action = RustCargoLambdaBuildAction (
87
- "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , self .subprocess_cargo_lambda , "arm64"
114
+ "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , None , self .subprocess_cargo_lambda , "arm64"
88
115
)
89
116
self .assertEqual (
90
117
action .build_command (),
@@ -95,7 +122,7 @@ def test_debug_build_cargo_command_with_flags(self):
95
122
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
96
123
flags = ["--package" , "package-in-workspace" ]
97
124
action = RustCargoLambdaBuildAction (
98
- "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , self .subprocess_cargo_lambda , "arm64" , flags = flags
125
+ "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , None , self .subprocess_cargo_lambda , "arm64" , flags = flags
99
126
)
100
127
self .assertEqual (
101
128
action .build_command (),
@@ -105,7 +132,7 @@ def test_debug_build_cargo_command_with_flags(self):
105
132
def test_debug_build_cargo_command_with_handler (self ):
106
133
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
107
134
action = RustCargoLambdaBuildAction (
108
- "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , self .subprocess_cargo_lambda , "arm64" , handler = "foo"
135
+ "source_dir" , {"cargo" : cargo }, BuildMode .DEBUG , None , self .subprocess_cargo_lambda , "arm64" , handler = "foo"
109
136
)
110
137
self .assertEqual (
111
138
action .build_command (),
@@ -115,7 +142,7 @@ def test_debug_build_cargo_command_with_handler(self):
115
142
def test_execute_happy_path (self ):
116
143
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
117
144
action = RustCargoLambdaBuildAction (
118
- "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda
145
+ "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda , None
119
146
)
120
147
action .execute ()
121
148
@@ -125,7 +152,7 @@ def test_execute_cargo_build_fail(self):
125
152
126
153
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
127
154
action = RustCargoLambdaBuildAction (
128
- "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda
155
+ "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda , None
129
156
)
130
157
with self .assertRaises (ActionFailedError ) as err_assert :
131
158
action .execute ()
@@ -136,7 +163,7 @@ def test_execute_happy_with_logger(self):
136
163
with patch .object (LOG , "debug" ) as mock_warning :
137
164
cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
138
165
action = RustCargoLambdaBuildAction (
139
- "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda
166
+ "source_dir" , {"cargo" : cargo }, BuildMode .RELEASE , self .subprocess_cargo_lambda , None
140
167
)
141
168
out = action .execute ()
142
169
self .assertEqual (out , "out" )
0 commit comments