]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-11115] tests for the Ceph package module
authorAlfredo Deza <adeza@redhat.com>
Wed, 12 Aug 2015 12:50:15 +0000 (08:50 -0400)
committerAlfredo Deza <adeza@redhat.com>
Thu, 13 Aug 2015 12:32:08 +0000 (08:32 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
ceph_deploy/tests/unit/util/test_packages.py [new file with mode: 0644]

diff --git a/ceph_deploy/tests/unit/util/test_packages.py b/ceph_deploy/tests/unit/util/test_packages.py
new file mode 100644 (file)
index 0000000..056f79d
--- /dev/null
@@ -0,0 +1,43 @@
+from mock import Mock, patch
+from ceph_deploy.exc import ExecutableNotFound
+from ceph_deploy.util import packages
+
+
+class TestCephIsInstalled(object):
+
+    def test_installed(self):
+        with patch('ceph_deploy.util.packages.system'):
+            c = packages.Ceph(Mock())
+            assert c.installed is True
+
+    def test_not_installed(self):
+        with patch('ceph_deploy.util.packages.system') as fsystem:
+            bad_executable = Mock(
+                side_effect=ExecutableNotFound('host', 'ceph')
+            )
+            fsystem.executable_path = bad_executable
+            c = packages.Ceph(Mock())
+            assert c.installed is False
+
+
+class TestCephVersion(object):
+
+    def test_executable_not_found(self):
+        with patch('ceph_deploy.util.packages.system') as fsystem:
+            bad_executable = Mock(
+                side_effect=ExecutableNotFound('host', 'ceph')
+            )
+            fsystem.executable_path = bad_executable
+            c = packages.Ceph(Mock())
+            assert c._get_version_output() == ''
+
+    def test_output_is_unusable(self):
+        _check = Mock(return_value=('', '', 1))
+        c = packages.Ceph(Mock(), _check=_check)
+        assert c._get_version_output() == ''
+
+    def test_output_usable(self):
+        version = 'ceph version 9.0.1-kjh234h123hd (asdf78asdjh234)'
+        _check = Mock(return_value=(version, '', 1))
+        c = packages.Ceph(Mock(), _check=_check)
+        assert c._get_version_output() == '9.0.1-kjh234h123hd'