]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-volume tests verify get_file_contents utility
authorAlfredo Deza <adeza@redhat.com>
Wed, 2 May 2018 23:48:23 +0000 (19:48 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 4 May 2018 17:19:27 +0000 (13:19 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/tests/util/test_system.py

index 690147cb29b3091b833ae174c74a4f361075ac89..bf71e8746b739547bbf5efaaa1090e6f273807d6 100644 (file)
@@ -168,6 +168,30 @@ class TestIsBinary(object):
         assert system.is_binary(binary_path) is False
 
 
+class TestGetFileContents(object):
+
+    def test_path_does_not_exist(self, tmpdir):
+        filepath = os.path.join(str(tmpdir), 'doesnotexist')
+        assert system.get_file_contents(filepath, 'default') == 'default'
+
+    def test_path_has_contents(self, tmpfile):
+        interesting_file = tmpfile(contents="1")
+        result = system.get_file_contents(interesting_file)
+        assert result == "1"
+
+    def test_path_has_multiline_contents(self, tmpfile):
+        interesting_file = tmpfile(contents="0\n1")
+        result = system.get_file_contents(interesting_file)
+        assert result == "0\n1"
+
+    def test_exception_returns_default(self, tmpfile):
+        interesting_file = tmpfile(contents="0")
+        # remove read, causes IOError
+        os.chmod(interesting_file, 0o000)
+        result = system.get_file_contents(interesting_file)
+        assert result == ''
+
+
 class TestWhich(object):
 
     def test_executable_exists_but_is_not_file(self, monkeypatch):