2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
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)`
|
|
|
|
:copyright: © 2013 by the SaltStack Team, see AUTHORS for more details
|
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
|
|
|
|
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
|
|
|
|
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 = (
|
2013-09-19 17:42:37 +00:00
|
|
|
('v0.12.0-19-g767d4f9', (0, 12, 0, 0, 19, 'g767d4f9'), None),
|
|
|
|
('v0.12.0-85-g2880105', (0, 12, 0, 0, 85, 'g2880105'), None),
|
|
|
|
('debian/0.11.1+ds-1-3-ga0afcbd',
|
2013-09-19 17:50:51 +00:00
|
|
|
(0, 11, 1, 0, 3, 'ga0afcbd'), '0.11.1-3-ga0afcbd'),
|
2013-09-19 17:42:37 +00:00
|
|
|
('0.12.1', (0, 12, 1, 0, 0, None), None),
|
|
|
|
('0.12.1', (0, 12, 1, 0, 0, None), None),
|
|
|
|
('0.17.0rc1', (0, 17, 0, 1, 0, None), None),
|
|
|
|
('v0.17.0rc1-1-g52ebdfd', (0, 17, 0, 1, 1, 'g52ebdfd'), None),
|
|
|
|
|
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:
|
|
|
|
version = \
|
|
|
|
strip_initial_non_numbers_regex.search(vs).group('vs')
|
|
|
|
|
|
|
|
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'),
|
2013-09-19 17:42:37 +00:00
|
|
|
)
|
|
|
|
for v1, v2 in examples:
|
|
|
|
self.assertTrue(SaltStackVersion.parse(v1) > v2)
|
|
|
|
self.assertTrue(SaltStackVersion.parse(v2) < v1)
|
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)
|