add apt unittest
This commit is contained in:
parent
80d520dde8
commit
e360582c4a
3 changed files with 47 additions and 3 deletions
|
@ -230,10 +230,10 @@ def expand_dpkg_options(dpkg_options_compressed):
|
||||||
def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
|
def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
|
||||||
new_pkgspec = []
|
new_pkgspec = []
|
||||||
for name_or_fnmatch_or_version in pkgspec:
|
for name_or_fnmatch_or_version in pkgspec:
|
||||||
pkgname_or_fnmatch_pattern = name_or_fnmatch_or_version.split("=")[0]
|
pkgname_or_fnmatch_pattern, version = package_split(name_or_fnmatch_or_version)
|
||||||
# note that any of these chars is not allowed in a (debian) pkgname
|
# note that any of these chars is not allowed in a (debian) pkgname
|
||||||
if [c for c in pkgname_or_fnmatch_pattern if c in "*?[]!"]:
|
if [c for c in pkgname_or_fnmatch_pattern if c in "*?[]!"]:
|
||||||
if "=" in pkgname_or_fnmatch_pattern:
|
if version:
|
||||||
m.fail_json(msg="pkgname wildcard and version can not be mixed")
|
m.fail_json(msg="pkgname wildcard and version can not be mixed")
|
||||||
# handle multiarch pkgnames, the idea is that "apt*" should
|
# handle multiarch pkgnames, the idea is that "apt*" should
|
||||||
# only select native packages. But "apt*:i386" should still work
|
# only select native packages. But "apt*:i386" should still work
|
||||||
|
@ -568,4 +568,6 @@ def main():
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
# FIXME: if __name__ == "__main__": ?
|
||||||
|
if "ANSIBLE_IN_HAPPY_UNITTEST_LAND" not in os.environ:
|
||||||
main()
|
main()
|
||||||
|
|
0
lib/ansible/modules/tests/__init__.py
Normal file
0
lib/ansible/modules/tests/__init__.py
Normal file
42
lib/ansible/modules/tests/test_apt.py
Normal file
42
lib/ansible/modules/tests/test_apt.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import collections
|
||||||
|
import mock
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
# FIXME: this is not super elegant
|
||||||
|
os.environ["ANSIBLE_IN_HAPPY_UNITTEST_LAND"] = "1"
|
||||||
|
from packaging.apt import (
|
||||||
|
expand_pkgspec_from_fnmatches,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AptExpandPkgspecTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
FakePackage = collections.namedtuple("Package", ("name",))
|
||||||
|
self.fake_cache = [ FakePackage("apt"),
|
||||||
|
FakePackage("apt-utils"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_trivil(self):
|
||||||
|
foo = ["apt"]
|
||||||
|
self.assertEqual(
|
||||||
|
expand_pkgspec_from_fnmatches(None, foo, self.fake_cache), foo)
|
||||||
|
|
||||||
|
def test_bug_28(self):
|
||||||
|
foo = ["apt=1.0*"]
|
||||||
|
self.assertEqual(
|
||||||
|
expand_pkgspec_from_fnmatches(None, foo, self.fake_cache), foo)
|
||||||
|
|
||||||
|
def test_pkgname_wildcard_version_wildcard_fails(self):
|
||||||
|
foo = ["apt*=1.0*"]
|
||||||
|
m_mock = mock.Mock()
|
||||||
|
expand_pkgspec_from_fnmatches(m_mock, foo, self.fake_cache)
|
||||||
|
self.assertTrue(m_mock.fail_json.called)
|
||||||
|
|
||||||
|
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"])
|
Loading…
Reference in a new issue