test_spm.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import
  4. import os
  5. # Import Salt Testing libs
  6. from tests.support.case import ShellCase, SPMCase
  7. class SPMTest(ShellCase, SPMCase):
  8. '''
  9. Test spm script
  10. '''
  11. def test_spm_help(self):
  12. '''
  13. test --help argument for spm
  14. '''
  15. expected_args = ['--version', '--assume-yes', '--help']
  16. output = self.run_spm('--help')
  17. for arg in expected_args:
  18. self.assertIn(arg, ''.join(output))
  19. def test_spm_bad_arg(self):
  20. '''
  21. test correct output when bad argument passed
  22. '''
  23. expected_args = ['--version', '--assume-yes', '--help']
  24. output = self.run_spm('doesnotexist')
  25. for arg in expected_args:
  26. self.assertIn(arg, ''.join(output))
  27. def test_spm_assume_yes(self):
  28. '''
  29. test spm install with -y arg
  30. '''
  31. config = self._spm_config(assume_yes=False)
  32. self._spm_build_files(config)
  33. spm_file = os.path.join(config['spm_build_dir'],
  34. 'apache-201506-2.spm')
  35. build = self.run_spm('build {0} -c {1}'.format(self.formula_dir,
  36. self._tmp_spm))
  37. install = self.run_spm('install {0} -c {1} -y'.format(spm_file,
  38. self._tmp_spm))
  39. self.assertTrue(os.path.exists(os.path.join(config['formula_path'],
  40. 'apache', 'apache.sls')))
  41. def test_spm_force(self):
  42. '''
  43. test spm install with -f arg
  44. '''
  45. config = self._spm_config(assume_yes=False)
  46. self._spm_build_files(config)
  47. spm_file = os.path.join(config['spm_build_dir'],
  48. 'apache-201506-2.spm')
  49. build = self.run_spm('build {0} -c {1}'.format(self.formula_dir,
  50. self._tmp_spm))
  51. install = self.run_spm('install {0} -c {1} -y'.format(spm_file,
  52. self._tmp_spm))
  53. self.assertTrue(os.path.exists(os.path.join(config['formula_path'],
  54. 'apache', 'apache.sls')))
  55. # check if it forces the install after its already been installed it
  56. install = self.run_spm('install {0} -c {1} -y -f'.format(spm_file,
  57. self._tmp_spm))
  58. self.assertEqual(['... installing apache'], install)