11from unittest import TestCase
22from unittest .mock import patch
3+ from parameterized import parameterized
34import io
45import logging
56import os
@@ -43,9 +44,35 @@ def which(cmd, executable_search_paths):
4344 proc = SubprocessCargoLambda (which = which , osutils = self .osutils )
4445 self .subprocess_cargo_lambda = proc
4546
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+
4673 def test_release_build_cargo_command_without_release_mode (self ):
4774 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 )
4976 self .assertEqual (
5077 action .build_command (),
5178 ["path/to/cargo" , "lambda" , "build" , "--release" ],
@@ -54,7 +81,7 @@ def test_release_build_cargo_command_without_release_mode(self):
5481 def test_release_build_cargo_command (self ):
5582 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
5683 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
5885 )
5986 self .assertEqual (
6087 action .build_command (),
@@ -64,7 +91,7 @@ def test_release_build_cargo_command(self):
6491 def test_release_build_cargo_command_with_target (self ):
6592 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
6693 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"
6895 )
6996 self .assertEqual (
7097 action .build_command (),
@@ -74,7 +101,7 @@ def test_release_build_cargo_command_with_target(self):
74101 def test_debug_build_cargo_command (self ):
75102 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
76103 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
78105 )
79106 self .assertEqual (
80107 action .build_command (),
@@ -84,7 +111,7 @@ def test_debug_build_cargo_command(self):
84111 def test_debug_build_cargo_command_with_architecture (self ):
85112 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
86113 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"
88115 )
89116 self .assertEqual (
90117 action .build_command (),
@@ -95,7 +122,7 @@ def test_debug_build_cargo_command_with_flags(self):
95122 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
96123 flags = ["--package" , "package-in-workspace" ]
97124 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
99126 )
100127 self .assertEqual (
101128 action .build_command (),
@@ -105,7 +132,7 @@ def test_debug_build_cargo_command_with_flags(self):
105132 def test_debug_build_cargo_command_with_handler (self ):
106133 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
107134 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"
109136 )
110137 self .assertEqual (
111138 action .build_command (),
@@ -115,7 +142,7 @@ def test_debug_build_cargo_command_with_handler(self):
115142 def test_execute_happy_path (self ):
116143 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
117144 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
119146 )
120147 action .execute ()
121148
@@ -125,7 +152,7 @@ def test_execute_cargo_build_fail(self):
125152
126153 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
127154 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
129156 )
130157 with self .assertRaises (ActionFailedError ) as err_assert :
131158 action .execute ()
@@ -136,7 +163,7 @@ def test_execute_happy_with_logger(self):
136163 with patch .object (LOG , "debug" ) as mock_warning :
137164 cargo = BinaryPath (None , None , None , binary_path = "path/to/cargo" )
138165 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
140167 )
141168 out = action .execute ()
142169 self .assertEqual (out , "out" )
0 commit comments