Beispiel #1
0
 def test_parse_go_delve_api_version_called_for_go_runtimes(
         self, parse_go_delve_api_version_mock):
     debug_args_list = Mock()
     LambdaDebugSettings.get_debug_settings(1234, debug_args_list, {},
                                            Runtime.go1x.value, {})
     parse_go_delve_api_version_mock.assert_called_once_with(
         debug_args_list)
Beispiel #2
0
    def _get_debug_settings(runtime, debug_options=None):  # pylint: disable=too-many-branches
        """
        Returns the entry point for the container. The default value for the entry point is already configured in the
        Dockerfile. We override this default specifically when enabling debugging. The overridden entry point includes
        a few extra flags to start the runtime in debug mode.

        :param string runtime: Lambda function runtime name.
        :param DebugContext debug_options: Optional. Debug context for the function (includes port, args, and path).
        :return list: List containing the new entry points. Each element in the list is one portion of the command.
            ie. if command is ``node index.js arg1 arg2``, then this list will be ["node", "index.js", "arg1", "arg2"]
        """

        entry = LambdaContainer._DEFAULT_ENTRYPOINT
        if not debug_options:
            return entry, {}

        debug_ports = debug_options.debug_ports
        container_env_vars = debug_options.container_env_vars
        if not debug_ports:
            return entry, {}

        debug_port = debug_ports[0]
        debug_args_list = []

        if debug_options.debug_args:
            debug_args_list = debug_options.debug_args.split(" ")
        # configs from: https://github.com/lambci/docker-lambda
        # to which we add the extra debug mode options
        return LambdaDebugSettings.get_debug_settings(
            debug_port=debug_port,
            debug_args_list=debug_args_list,
            _container_env_vars=container_env_vars,
            runtime=runtime,
            options=LambdaContainer._DEBUG_ENTRYPOINT_OPTIONS,
        )
Beispiel #3
0
 def test_unrecognized_delve_api_version_parsing(self, debug_arg_list):
     with patch("samcli.local.docker.lambda_debug_settings.LOG.warning"
                ) as warning_mock:
         self.assertEqual(
             LambdaDebugSettings.parse_go_delve_api_version(debug_arg_list),
             1)
         warning_mock.assert_called_once_with(
             'Ignoring unrecognized arguments: %s. Only "-delveAPI" is supported.',
             debug_arg_list)
Beispiel #4
0
 def test_parse_go_delve_api_version_not_called_for_other_runtimes(
         self, runtime, parse_go_delve_api_version_mock):
     LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value, {})
     parse_go_delve_api_version_mock.assert_not_called()
Beispiel #5
0
 def test_debugging_not_supported_raised(self, runtime,
                                         debug_settings_mock):
     with self.assertRaises(DebuggingNotSupported):
         LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value,
                                                {})
     debug_settings_mock.assert_not_called()
Beispiel #6
0
 def test_only_one_debug_setting_is_created(self, runtime,
                                            debug_settings_mock):
     LambdaDebugSettings.get_debug_settings(1234, [], {}, runtime.value, {})
     debug_settings_mock.assert_called_once()
Beispiel #7
0
 def test_delve_api_version_parsing(self, debug_arg_list,
                                    expected_api_version):
     self.assertEqual(
         LambdaDebugSettings.parse_go_delve_api_version(debug_arg_list),
         expected_api_version)