2013-01-19 02:31:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2013-09-16 16:24:00 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2014-05-26 18:26:15 +00:00
|
|
|
|
2013-09-16 16:24:00 +00:00
|
|
|
|
2013-01-19 02:31:00 +00:00
|
|
|
tests.unit.version_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test salt's regex git describe version parsing
|
|
|
|
'''
|
|
|
|
|
2013-02-06 04:59:26 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2013-02-06 04:59:26 +00:00
|
|
|
import re
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import TestCase
|
2013-06-27 00:30:49 +00:00
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
|
|
|
|
ensure_in_syspath('../')
|
|
|
|
|
|
|
|
# Import Salt libs
|
2013-09-19 17:42:37 +00:00
|
|
|
from salt.version import SaltStackVersion
|
2013-06-24 22:53:59 +00:00
|
|
|
|
2013-01-19 02:31:00 +00:00
|
|
|
|
|
|
|
class VersionTestCase(TestCase):
|
2013-09-19 17:42:37 +00:00
|
|
|
def test_version_parsing(self):
|
|
|
|
strip_initial_non_numbers_regex = re.compile(r'(?:[^\d]+)?(?P<vs>.*)')
|
2013-01-19 02:31:00 +00:00
|
|
|
expect = (
|
2014-07-29 21:19:34 +00:00
|
|
|
('v0.12.0-19-g767d4f9', (0, 12, 0, 0, 0, 19, 'g767d4f9'), None),
|
|
|
|
('v0.12.0-85-g2880105', (0, 12, 0, 0, 0, 85, 'g2880105'), None),
|
2013-09-19 17:42:37 +00:00
|
|
|
('debian/0.11.1+ds-1-3-ga0afcbd',
|
2014-07-29 21:19:34 +00:00
|
|
|
(0, 11, 1, 0, 0, 3, 'ga0afcbd'), '0.11.1-3-ga0afcbd'),
|
|
|
|
('0.12.1', (0, 12, 1, 0, 0, 0, None), None),
|
|
|
|
('0.12.1', (0, 12, 1, 0, 0, 0, None), None),
|
|
|
|
('0.17.0rc1', (0, 17, 0, 0, 1, 0, None), None),
|
|
|
|
('v0.17.0rc1-1-g52ebdfd', (0, 17, 0, 0, 1, 1, 'g52ebdfd'), None),
|
|
|
|
('v2014.1.4.1', (2014, 1, 4, 1, 0, 0, None), None),
|
2014-07-29 21:28:05 +00:00
|
|
|
('v2014.1.4.1rc3-n/a-abcdefgh', (2014, 1, 4, 1, 3, -1, 'abcdefgh'), None),
|
|
|
|
('v3.4.1.1', (3, 4, 1, 1, 0, 0, None), None)
|
2013-09-19 17:42:37 +00:00
|
|
|
|
2013-01-19 02:31:00 +00:00
|
|
|
)
|
|
|
|
|
2013-09-19 17:42:37 +00:00
|
|
|
for vs, full_info, version in expect:
|
|
|
|
saltstack_version = SaltStackVersion.parse(vs)
|
2013-01-19 02:31:00 +00:00
|
|
|
self.assertEqual(
|
2013-09-19 17:42:37 +00:00
|
|
|
saltstack_version.full_info, full_info
|
2013-01-19 02:31:00 +00:00
|
|
|
)
|
2013-09-19 17:42:37 +00:00
|
|
|
if version is None:
|
2014-07-29 21:19:34 +00:00
|
|
|
version = strip_initial_non_numbers_regex.search(vs).group('vs')
|
2013-09-19 17:42:37 +00:00
|
|
|
self.assertEqual(saltstack_version.string, version)
|
|
|
|
|
|
|
|
def test_version_comparison(self):
|
|
|
|
examples = (
|
|
|
|
('debian/0.11.1+ds-1-3-ga0afcbd', '0.11.1+ds-2'),
|
|
|
|
('v0.12.0-85-g2880105', 'v0.12.0-19-g767d4f9'),
|
|
|
|
('v0.17.0rc1-1-g52ebdfd', '0.17.0rc1'),
|
2013-10-04 08:52:53 +00:00
|
|
|
('v0.17.0', 'v0.17.0rc1'),
|
|
|
|
('Hydrogen', '0.17.0'),
|
|
|
|
('Helium', 'Hydrogen'),
|
2014-07-29 21:48:33 +00:00
|
|
|
('v2014.1.4.1-n/a-abcdefgh', 'v2014.1.4.1rc3-n/a-abcdefgh'),
|
|
|
|
('v2014.1.4.1-1-abcdefgh', 'v2014.1.4.1-n/a-abcdefgh')
|
2013-09-19 17:42:37 +00:00
|
|
|
)
|
2014-07-29 21:47:52 +00:00
|
|
|
for higher_version, lower_version in examples:
|
|
|
|
self.assertTrue(SaltStackVersion.parse(higher_version) > lower_version)
|
|
|
|
self.assertTrue(SaltStackVersion.parse(lower_version) < higher_version)
|
2013-01-19 02:31:00 +00:00
|
|
|
|
2013-10-04 08:52:53 +00:00
|
|
|
def test_unparsable_version(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
SaltStackVersion.from_name('Drunk')
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
SaltStackVersion.parse('Drunk')
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(VersionTestCase, needs_daemon=False)
|