@@ -421,6 +421,20 @@ def test_image_pull_failure_raises_click_exception(self):
421421 container ._pull_image_if_needed ()
422422 self .assertIn ("Failed to pull emulator image" , str (context .exception ))
423423
424+ @patch ("samcli.local.docker.durable_functions_emulator_container.is_image_current" )
425+ def test_image_pull_failure_with_existing_local_image_logs_debug_message (self , mock_is_current ):
426+ """Test that image pull failure with existing local image logs debug message before raising exception"""
427+ container = self ._create_container ()
428+ mock_image = Mock ()
429+ self .mock_docker_client .images .get .return_value = mock_image
430+ mock_is_current .return_value = False
431+ self .mock_docker_client .images .pull .side_effect = Exception ("Network timeout" )
432+
433+ with (self .assertLogs ("samcli.local.docker.durable_functions_emulator_container" , level = "DEBUG" ) as log ,):
434+ container ._pull_image_if_needed ()
435+
436+ self .assertTrue (any ("Using existing local emulator image since we failed to pull" in msg for msg in log .output ))
437+
424438 @patch ("samcli.local.docker.durable_functions_emulator_container.requests" )
425439 def test_start_durable_execution_success (self , mock_requests ):
426440 """Test that start_durable_execution() posts correct payload and returns response json"""
@@ -690,3 +704,18 @@ def test_stop_captures_logs_before_stopping(self):
690704
691705 container ._capture_emulator_logs .assert_called_once ()
692706 self .mock_container .stop .assert_called_once ()
707+
708+ @patch ("samcli.local.docker.durable_functions_emulator_container.is_image_current" )
709+ def test_skip_pull_image_with_existing_local_image_logs_debug_and_returns_early (self , mock_is_current ):
710+ """Test that _skip_pull_image=True with existing local image logs debug message and returns early"""
711+ container = self ._create_container ()
712+ container ._skip_pull_image = True
713+ mock_image = Mock ()
714+ mock_is_current .return_value = False
715+ self .mock_docker_client .images .get .return_value = mock_image
716+
717+ with self .assertLogs ("samcli.local.docker.durable_functions_emulator_container" , level = "DEBUG" ) as log :
718+ container ._pull_image_if_needed ()
719+
720+ self .assertTrue (any ("Skipping pulling new emulator image" in msg for msg in log .output ))
721+ self .mock_docker_client .images .pull .assert_not_called ()
0 commit comments