1
0

test_arguments.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test Salt's argument parser
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  7. # Import Salt Testing libs
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import requires_salt_modules
  10. # Import Salt libs
  11. import salt.utils.args
  12. @requires_salt_modules('test.ping', 'test.arg')
  13. class ArgumentTestCase(ModuleCase):
  14. def test_unsupported_kwarg(self):
  15. '''
  16. Test passing a non-supported keyword argument. The relevant code that
  17. checks for invalid kwargs is located in salt/minion.py, within the
  18. 'load_args_and_kwargs' function.
  19. '''
  20. self.assertIn(
  21. ("ERROR executing 'test.ping': The following keyword arguments"),
  22. self.run_function('test.ping', foo='bar')
  23. )
  24. def test_kwarg_name_containing_dashes(self):
  25. '''
  26. Tests the arg parser to ensure that kwargs with dashes in the arg name
  27. are properly identified as kwargs. If this fails, then the KWARG_REGEX
  28. variable in salt/utils/__init__.py needs to be fixed.
  29. '''
  30. # We need to use parse_input here because run_function now requires
  31. # kwargs to be passed in as *actual* kwargs, and dashes are not valid
  32. # characters in Python kwargs.
  33. self.assertEqual(
  34. self.run_function(
  35. 'test.arg', salt.utils.args.parse_input(['foo-bar=baz'])
  36. ).get('kwargs', {}).get('foo-bar'),
  37. 'baz'
  38. )
  39. def test_argument_containing_pound_sign(self):
  40. '''
  41. Tests the argument parsing to ensure that a CLI argument with a pound
  42. sign doesn't have the pound sign interpreted as a comment and removed.
  43. See https://github.com/saltstack/salt/issues/8585 for more info.
  44. '''
  45. arg = 'foo bar #baz'
  46. self.assertEqual(
  47. self.run_function('test.echo', [arg]),
  48. arg
  49. )