aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Jaggars <jjaggars@redhat.com>2012-03-05 10:30:59 -0600
committerJesse Jaggars <jjaggars@redhat.com>2012-03-05 10:30:59 -0600
commitc10115652a795d0c7971ec9b03c4c58742063ddf (patch)
tree4c14fa591b807350f6db6c7da10f1430049602f5 /tests
parent83c6e09756bd228dc76e7a84646de5a9f5b5e694 (diff)
downloadsos-c10115652a795d0c7971ec9b03c4c58742063ddf.tar.gz
Refactoring PackageManagers and Archives
Pulled up PackageManager implementation to simplify subclass responsibilities Moved compress method to Archive classes Re-organized utilities.py Added tests to exercise more utilities methods
Diffstat (limited to 'tests')
-rw-r--r--tests/archive_tests.py26
-rw-r--r--tests/path/to/leaf0
-rwxr-xr-xtests/test_exe.py2
-rw-r--r--tests/utilities_tests.py48
4 files changed, 74 insertions, 2 deletions
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index f982be0a..8a542f73 100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
@@ -66,13 +66,27 @@ class ZipFileArchiveTest(unittest.TestCase):
afp = self.zf.open_file('tests/string_test.txt')
self.assertEquals('this is my new content', afp.read())
+ def test_make_link(self):
+ self.zf.add_file('tests/ziptest')
+ self.zf.add_link('tests/ziptest', 'link_name')
+
+ self.zf.close()
+ try:
+ self.check_for_file('test/link_name')
+ self.fail("link should not exist")
+ except KeyError:
+ pass
+
+ def test_compress(self):
+ self.assertEquals(self.zf.compress("zip"), self.zf.name())
+
class TarFileArchiveTest(unittest.TestCase):
def setUp(self):
self.tf = TarFileArchive('test')
def tearDown(self):
- os.unlink('test.tar')
+ os.unlink(self.tf.name())
def check_for_file(self, filename):
rtf = tarfile.open('test.tar')
@@ -126,5 +140,15 @@ class TarFileArchiveTest(unittest.TestCase):
afp = self.tf.open_file('tests/string_test.txt')
self.assertEquals('this is my new content', afp.read())
+ def test_make_link(self):
+ self.tf.add_file('tests/ziptest')
+ self.tf.add_link('tests/ziptest', 'link_name')
+
+ self.tf.close()
+ self.check_for_file('test/link_name')
+
+ def test_compress(self):
+ name = self.tf.compress("gzip")
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/path/to/leaf b/tests/path/to/leaf
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/path/to/leaf
diff --git a/tests/test_exe.py b/tests/test_exe.py
new file mode 100755
index 00000000..f35d93f0
--- /dev/null
+++ b/tests/test_exe.py
@@ -0,0 +1,2 @@
+#!/usr/bin/env python
+print "executed"
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
index d5115928..fbfc9a55 100644
--- a/tests/utilities_tests.py
+++ b/tests/utilities_tests.py
@@ -2,9 +2,11 @@ import os.path
import unittest
from StringIO import StringIO
-from sos.utilities import grep, DirTree, checksum
+from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sosGetCommandOutput, find
import sos
+TEST_DIR = os.path.dirname(__file__)
+
class GrepTest(unittest.TestCase):
def test_file_obj(self):
@@ -30,8 +32,52 @@ class DirTreeTest(unittest.TestCase):
t = DirTree(os.path.dirname(sos.__file__)).as_string()
self.assertTrue('Makefile' in t)
+
class ChecksumTest(unittest.TestCase):
def test_simple_hash(self):
self.assertEquals(checksum(StringIO('this is a test'), algorithm="sha256"),
'2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c')
+
+ def test_hash_loading(self):
+ # not the greatest test, since we are asking the policy to pick for us
+ name = get_hash_name()
+ self.assertTrue(name in ('md5', 'sha256'))
+
+
+class ExecutableTest(unittest.TestCase):
+
+ def test_nonexe_file(self):
+ path = os.path.join(TEST_DIR, 'utility_tests.py')
+ self.assertFalse(is_executable(path))
+
+ def test_exe_file(self):
+ path = os.path.join(TEST_DIR, 'test_exe.py')
+ self.assertTrue(is_executable(path))
+
+ def test_output(self):
+ path = os.path.join(TEST_DIR, 'test_exe.py')
+ ret, out, junk = sosGetCommandOutput(path)
+ self.assertEquals(ret, 0)
+ self.assertEquals(out, "executed")
+
+ def test_output_non_exe(self):
+ path = os.path.join(TEST_DIR, 'utility_tests.py')
+ ret, out, junk = sosGetCommandOutput(path)
+ self.assertEquals(ret, 127)
+ self.assertEquals(out, "")
+
+
+class FindTest(unittest.TestCase):
+
+ def test_find_leaf(self):
+ leaves = find("leaf", TEST_DIR)
+ self.assertTrue(any(name.endswith("leaf") for name in leaves))
+
+ def test_too_shallow(self):
+ leaves = find("leaf", TEST_DIR, max_depth=1)
+ self.assertFalse(any(name.endswith("leaf") for name in leaves))
+
+ def test_not_in_pattern(self):
+ leaves = find("leaf", TEST_DIR, path_pattern="tests/path")
+ self.assertFalse(any(name.endswith("leaf") for name in leaves))