mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 12:51:25 -07:00
Some algorithmic unittests for the apt and docker modules
This commit is contained in:
parent
13532027ff
commit
7e1fbe2e03
4 changed files with 69 additions and 0 deletions
50
test/units/modules/core/test_apt.py
Normal file
50
test/units/modules/core/test_apt.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import collections
|
||||
import mock
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from ansible.modules.core.packaging.os.apt import (
|
||||
expand_pkgspec_from_fnmatches,
|
||||
)
|
||||
except:
|
||||
# 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
|
||||
|
||||
|
||||
@unittest.skipIf(sys.version_info[0] >= 3, "Python 3 is not supported on targets (yet)")
|
||||
class AptExpandPkgspecTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
FakePackage = collections.namedtuple("Package", ("name",))
|
||||
self.fake_cache = [ FakePackage("apt"),
|
||||
FakePackage("apt-utils"),
|
||||
FakePackage("not-selected"),
|
||||
]
|
||||
|
||||
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"])
|
Loading…
Add table
Add a link
Reference in a new issue