2016-04-27 16:23:31 +02:00
|
|
|
import collections
|
|
|
|
import sys
|
2016-04-27 19:45:39 +02:00
|
|
|
|
2018-10-13 05:01:14 +02:00
|
|
|
from units.compat import mock
|
|
|
|
from units.compat import unittest
|
2016-04-27 16:23:31 +02:00
|
|
|
|
|
|
|
try:
|
2016-12-06 17:29:16 +01:00
|
|
|
from ansible.modules.packaging.os.apt import (
|
2016-04-27 16:23:31 +02:00
|
|
|
expand_pkgspec_from_fnmatches,
|
|
|
|
)
|
2018-09-08 02:59:46 +02:00
|
|
|
except Exception:
|
2016-04-27 16:23:31 +02:00
|
|
|
# Need some more module_utils work (porting urls.py) before we can test
|
|
|
|
# modules. So don't error out in this case.
|
|
|
|
if sys.version_info[0] >= 3:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class AptExpandPkgspecTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
FakePackage = collections.namedtuple("Package", ("name",))
|
2017-05-30 19:05:19 +02:00
|
|
|
self.fake_cache = [
|
|
|
|
FakePackage("apt"),
|
|
|
|
FakePackage("apt-utils"),
|
|
|
|
FakePackage("not-selected"),
|
2016-04-27 16:23:31 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def test_trivial(self):
|
|
|
|
foo = ["apt"]
|
|
|
|
self.assertEqual(
|
|
|
|
expand_pkgspec_from_fnmatches(None, foo, self.fake_cache), foo)
|
|
|
|
|
|
|
|
def test_version_wildcard(self):
|
|
|
|
foo = ["apt=1.0*"]
|
|
|
|
self.assertEqual(
|
|
|
|
expand_pkgspec_from_fnmatches(None, foo, self.fake_cache), foo)
|
|
|
|
|
|
|
|
def test_pkgname_wildcard_version_wildcard(self):
|
|
|
|
foo = ["apt*=1.0*"]
|
|
|
|
m_mock = mock.Mock()
|
|
|
|
self.assertEqual(
|
|
|
|
expand_pkgspec_from_fnmatches(m_mock, foo, self.fake_cache),
|
|
|
|
['apt', 'apt-utils'])
|
|
|
|
|
|
|
|
def test_pkgname_expands(self):
|
|
|
|
foo = ["apt*"]
|
|
|
|
m_mock = mock.Mock()
|
|
|
|
self.assertEqual(
|
|
|
|
expand_pkgspec_from_fnmatches(m_mock, foo, self.fake_cache),
|
|
|
|
["apt", "apt-utils"])
|