From 41f5ce80fa597e88ab1c749fea30b4a39492292f Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 27 Apr 2016 07:23:31 -0700 Subject: [PATCH] Some algorithmic unittests for the apt and docker modules --- test/units/modules/__init__.py | 0 test/units/modules/core/__init__.py | 0 test/units/modules/core/test_apt.py | 50 ++++++++++++++++++++++++++ test/units/modules/core/test_docker.py | 19 ++++++++++ 4 files changed, 69 insertions(+) create mode 100644 test/units/modules/__init__.py create mode 100644 test/units/modules/core/__init__.py create mode 100644 test/units/modules/core/test_apt.py create mode 100644 test/units/modules/core/test_docker.py diff --git a/test/units/modules/__init__.py b/test/units/modules/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/core/__init__.py b/test/units/modules/core/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/core/test_apt.py b/test/units/modules/core/test_apt.py new file mode 100644 index 00000000000..bd43a4aeae4 --- /dev/null +++ b/test/units/modules/core/test_apt.py @@ -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"]) diff --git a/test/units/modules/core/test_docker.py b/test/units/modules/core/test_docker.py new file mode 100644 index 00000000000..b8c8cf1e235 --- /dev/null +++ b/test/units/modules/core/test_docker.py @@ -0,0 +1,19 @@ +import collections +import os +import unittest + +from ansible.modules.core.cloud.docker.docker import get_split_image_tag + +class DockerSplitImageTagTestCase(unittest.TestCase): + + def test_trivial(self): + self.assertEqual(get_split_image_tag('test'), ('test', 'latest')) + + def test_with_org_name(self): + self.assertEqual(get_split_image_tag('ansible/centos7-ansible'), ('ansible/centos7-ansible', 'latest')) + + def test_with_tag(self): + self.assertEqual(get_split_image_tag('test:devel'), ('test', 'devel')) + + def test_with_tag_and_org_name(self): + self.assertEqual(get_split_image_tag('ansible/centos7-ansible:devel'), ('ansible/centos7-ansible', 'devel'))