@@ -22,32 +22,34 @@ def tearDown(self):
2222 self .subprocess_dotnet .reset_mock ()
2323
2424 def test_global_tool_install (self ):
25+ self .subprocess_dotnet .run .return_value = ""
2526 action = GlobalToolInstallAction (self .subprocess_dotnet )
2627 action .execute ()
27- self .subprocess_dotnet .run .assert_called_once_with (
28+ self .subprocess_dotnet .run .assert_any_call (["tool" , "list" , "-g" ])
29+ self .subprocess_dotnet .run .assert_any_call (
2830 ["tool" , "install" , "-g" , "Amazon.Lambda.Tools" , "--ignore-failed-sources" ]
2931 )
3032
31- def test_global_tool_update (self ):
32- self .subprocess_dotnet .run .side_effect = [DotnetCLIExecutionError (message = "Already Installed" ), None ]
33+ def test_global_tool_already_installed (self ):
34+ self .subprocess_dotnet .run .return_value = (
35+ "Package Id Version Commands\n "
36+ "--------------------------------------------------------------\n "
37+ "amazon.lambda.tools 5.3.0 dotnet-lambda\n "
38+ )
3339 action = GlobalToolInstallAction (self .subprocess_dotnet )
3440 action .execute ()
35- self .subprocess_dotnet .run .assert_any_call (
36- ["tool" , "install" , "-g" , "Amazon.Lambda.Tools" , "--ignore-failed-sources" ]
37- )
38- self .subprocess_dotnet .run .assert_any_call (
39- ["tool" , "update" , "-g" , "Amazon.Lambda.Tools" , "--ignore-failed-sources" ]
40- )
41+ self .subprocess_dotnet .run .assert_called_once_with (["tool" , "list" , "-g" ])
4142
42- def test_global_tool_update_failed (self ):
43+ def test_global_tool_install_failed (self ):
4344 self .subprocess_dotnet .run .side_effect = [
44- DotnetCLIExecutionError ( message = "Already Installed" ),
45- DotnetCLIExecutionError (message = "Updated Failed" ),
45+ "" , # tool list returns empty (not installed)
46+ DotnetCLIExecutionError (message = "Install Failed" ),
4647 ]
4748 action = GlobalToolInstallAction (self .subprocess_dotnet )
4849 self .assertRaises (ActionFailedError , action .execute )
4950
5051 def test_global_tool_parallel (self ):
52+ self .subprocess_dotnet .run .return_value = ""
5153 actions = [
5254 GlobalToolInstallAction (self .subprocess_dotnet ),
5355 GlobalToolInstallAction (self .subprocess_dotnet ),
@@ -58,9 +60,11 @@ def test_global_tool_parallel(self):
5860 for action in actions :
5961 executor .submit (action .execute )
6062
61- self .subprocess_dotnet .run .assert_called_once_with (
63+ self .subprocess_dotnet .run .assert_any_call (["tool" , "list" , "-g" ])
64+ self .subprocess_dotnet .run .assert_any_call (
6265 ["tool" , "install" , "-g" , "Amazon.Lambda.Tools" , "--ignore-failed-sources" ]
6366 )
67+ self .assertEqual (self .subprocess_dotnet .run .call_count , 2 )
6468
6569
6670class TestRunPackageAction (TestCase ):
0 commit comments