summaryrefslogtreecommitdiffstats
path: root/test/unit/gluster/test_gfapi.py
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-05-30 15:08:48 +0530
committerPrashanth Pai <ppai@redhat.com>2016-06-15 15:02:18 +0530
commitb111d50347076336b3e655178d967f8e5c8c9913 (patch)
treeb4ad1944d0379f560fae379efd27d69e7c12eb65 /test/unit/gluster/test_gfapi.py
parent759471ddcd76306b952bb2ee28f211afc9e24f3a (diff)
Add validation decorators
As glfs and glfd are pointers to memory locations, passing invalid values of glfs and glfd to the libgfapi C library can result in segfault. This patch introduces decorators that validate glfs and glfd before calling correspoding C APIs. Change-Id: I4e86bd8e436e23cd41f75f428d246939c820bb9c Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/unit/gluster/test_gfapi.py')
-rw-r--r--test/unit/gluster/test_gfapi.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py
index 3934a6f..86fa621 100644
--- a/test/unit/gluster/test_gfapi.py
+++ b/test/unit/gluster/test_gfapi.py
@@ -11,6 +11,7 @@
import unittest
import gluster
+import inspect
import os
import stat
import time
@@ -70,6 +71,36 @@ class TestFile(unittest.TestCase):
def tearDown(self):
gluster.gfapi.api.glfs_close = self._saved_glfs_close
+ def test_validate_init(self):
+ self.assertRaises(ValueError, File, None)
+ self.assertRaises(ValueError, File, "not_int")
+
+ try:
+ with File(None) as f:
+ pass
+ except ValueError:
+ pass
+ else:
+ self.fail("Expecting ValueError")
+
+ try:
+ with File("not_int") as f:
+ pass
+ except ValueError:
+ pass
+ else:
+ self.fail("Expecting ValueError")
+
+ def test_validate_glfd_decorator_applied(self):
+ for method_name, method_instance in \
+ inspect.getmembers(File, predicate=inspect.ismethod):
+ if not method_name.startswith('_'):
+ try:
+ wrapper_attribute = method_instance.__wrapped__.__name__
+ self.assertEqual(wrapper_attribute, method_name)
+ except AttributeError:
+ self.fail("Method File.%s isn't decorated" % (method_name))
+
def test_fchmod_success(self):
mock_glfs_fchmod = Mock()
mock_glfs_fchmod.return_value = 0