From 64ee880b1cbf6d1e1c3343c8f463257b447d1211 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 30 Jun 2008 00:13:38 +0200 Subject: [PATCH] unittests: add many checks for namespace ops The patch adds in many places checks for result correctness when using namespaces, and for the equality of non-ns versus ns usage. --- test/test_xattr.py | 86 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/test/test_xattr.py b/test/test_xattr.py index 49eff07..a5009b7 100644 --- a/test/test_xattr.py +++ b/test/test_xattr.py @@ -7,12 +7,14 @@ import os import errno import xattr +from xattr import NS_USER, XATTR_CREATE, XATTR_REPLACE TEST_DIR = os.environ.get("TESTDIR", ".") class xattrTest(unittest.TestCase): - USER_ATTR = "user.test" + USER_NN = "test" + USER_ATTR = "%s.%s" % (NS_USER, USER_NN) USER_VAL = "abc" MANYOPS_COUNT = 131072 @@ -53,7 +55,7 @@ class xattrTest(unittest.TestCase): self.failUnlessEqual(xattr.listxattr(item, symlink), []) self.failUnlessRaises(EnvironmentError, xattr.setxattr, item, self.USER_ATTR, self.USER_VAL, - xattr.XATTR_REPLACE) + XATTR_REPLACE) try: xattr.setxattr(item, self.USER_ATTR, self.USER_VAL, 0, symlink) except IOError, err: @@ -64,7 +66,7 @@ class xattrTest(unittest.TestCase): raise self.failUnlessRaises(EnvironmentError, xattr.setxattr, item, self.USER_ATTR, self.USER_VAL, - xattr.XATTR_CREATE) + XATTR_CREATE) self.failUnlessEqual(xattr.listxattr(item, symlink), [self.USER_ATTR]) self.failUnlessEqual(xattr.getxattr(item, self.USER_ATTR, symlink), self.USER_VAL) @@ -76,14 +78,24 @@ class xattrTest(unittest.TestCase): self.failUnlessRaises(EnvironmentError, xattr.removexattr, item, self.USER_ATTR) - def _checkListSetGet(self, item, symlink=False): + def _checkListSetGet(self, item, symlink=False, use_ns=False): """check list, set, get operations against an item""" self.failUnlessEqual(xattr.list(item, symlink), []) self.failUnlessRaises(EnvironmentError, xattr.set, item, self.USER_ATTR, self.USER_VAL, - flags=xattr.XATTR_REPLACE) + flags=XATTR_REPLACE) + self.failUnlessRaises(EnvironmentError, xattr.set, item, + self.USER_NN, self.USER_VAL, + flags=XATTR_REPLACE, + namespace=NS_USER) try: - xattr.set(item, self.USER_ATTR, self.USER_VAL, nofollow=symlink) + if use_ns: + xattr.set(item, self.USER_NN, self.USER_VAL, + namespace=NS_USER, + nofollow=symlink) + else: + xattr.set(item, self.USER_ATTR, self.USER_VAL, + nofollow=symlink) except IOError, err: if err.errno == errno.EPERM and symlink: # symlinks may fail, in which case we abort the rest @@ -92,17 +104,37 @@ class xattrTest(unittest.TestCase): raise self.failUnlessRaises(EnvironmentError, xattr.set, item, self.USER_ATTR, self.USER_VAL, - flags=xattr.XATTR_CREATE) - self.failUnlessEqual(xattr.list(item, symlink), [self.USER_ATTR]) + flags=XATTR_CREATE) + self.failUnlessRaises(EnvironmentError, xattr.set, item, + self.USER_NN, self.USER_VAL, + flags=XATTR_CREATE, + namespace=NS_USER) + self.failUnlessEqual(xattr.list(item, nofollow=symlink), + [self.USER_ATTR]) + self.failUnlessEqual(xattr.list(item, namespace=NS_USER, + nofollow=symlink), + [self.USER_NN]) self.failUnlessEqual(xattr.get(item, self.USER_ATTR, nofollow=symlink), self.USER_VAL) + self.failUnlessEqual(xattr.get(item, self.USER_NN, nofollow=symlink, + namespace=NS_USER), + self.USER_VAL) self.failUnlessEqual(xattr.get_all(item, nofollow=symlink), [(self.USER_ATTR, self.USER_VAL)]) - xattr.remove(item, self.USER_ATTR) + self.failUnlessEqual(xattr.get_all(item, nofollow=symlink, + namespace=NS_USER), + [(self.USER_NN, self.USER_VAL)]) + if use_ns: + xattr.remove(item, self.USER_NN, namespace=NS_USER) + else: + xattr.remove(item, self.USER_ATTR) self.failUnlessEqual(xattr.list(item, symlink), []) self.failUnlessEqual(xattr.get_all(item, nofollow=symlink), []) self.failUnlessRaises(EnvironmentError, xattr.remove, - item, self.USER_ATTR) + item, self.USER_ATTR, nofollow=symlink) + self.failUnlessRaises(EnvironmentError, xattr.remove, + item, self.USER_NN, namespace=NS_USER, + nofollow=symlink) def testNoXattrDeprecated(self): """test no attributes (deprecated functions)""" @@ -120,13 +152,21 @@ class xattrTest(unittest.TestCase): """test no attributes""" fh, fname = self._getfile() self.failUnlessEqual(xattr.list(fname), []) + self.failUnlessEqual(xattr.list(fname, namespace=NS_USER), []) self.failUnlessEqual(xattr.get_all(fname), []) + self.failUnlessEqual(xattr.get_all(fname, namespace=NS_USER), []) dname = self._getdir() self.failUnlessEqual(xattr.list(dname), []) + self.failUnlessEqual(xattr.list(dname, namespace=NS_USER), []) self.failUnlessEqual(xattr.get_all(dname), []) + self.failUnlessEqual(xattr.get_all(dname, namespace=NS_USER), []) sname = self._getsymlink() self.failUnlessEqual(xattr.list(sname, nofollow=True), []) + self.failUnlessEqual(xattr.list(sname, nofollow=True, + namespace=NS_USER), []) self.failUnlessEqual(xattr.get_all(sname, nofollow=True), []) + self.failUnlessEqual(xattr.get_all(sname, nofollow=True, + namespace=NS_USER), []) def testFileByNameDeprecated(self): """test set and retrieve one attribute by file name (deprecated)""" @@ -138,6 +178,7 @@ class xattrTest(unittest.TestCase): """test set and retrieve one attribute by file name""" fh, fname = self._getfile() self._checkListSetGet(fname) + self._checkListSetGet(fname, use_ns=True) os.close(fh) def testFileByDescriptorDeprecated(self): @@ -150,6 +191,7 @@ class xattrTest(unittest.TestCase): """test file descriptor operations""" fh, fname = self._getfile() self._checkListSetGet(fh) + self._checkListSetGet(fh, use_ns=True) os.close(fh) def testFileByObjectDeprecated(self): @@ -164,6 +206,7 @@ class xattrTest(unittest.TestCase): fh, fname = self._getfile() fo = os.fdopen(fh) self._checkListSetGet(fo) + self._checkListSetGet(fo, use_ns=True) fo.close() def testMixedAccessDeprecated(self): @@ -187,12 +230,20 @@ class xattrTest(unittest.TestCase): self.failUnlessEqual(xattr.list(fname), []) xattr.set(fname, self.USER_ATTR, self.USER_VAL) self.failUnlessEqual(xattr.list(fh), [self.USER_ATTR]) + self.failUnlessEqual(xattr.list(fh, namespace=NS_USER), + [self.USER_NN]) self.failUnlessEqual(xattr.get(fo, self.USER_ATTR), self.USER_VAL) + self.failUnlessEqual(xattr.get(fo, self.USER_NN, namespace=NS_USER), + self.USER_VAL) self.failUnlessEqual(xattr.get_all(fo), [(self.USER_ATTR, self.USER_VAL)]) + self.failUnlessEqual(xattr.get_all(fo, namespace=NS_USER), + [(self.USER_NN, self.USER_VAL)]) self.failUnlessEqual(xattr.get_all(fname), [(self.USER_ATTR, self.USER_VAL)]) + self.failUnlessEqual(xattr.get_all(fname, namespace=NS_USER), + [(self.USER_NN, self.USER_VAL)]) def testDirOpsDeprecated(self): """test attribute setting on directories (deprecated functions)""" @@ -203,6 +254,7 @@ class xattrTest(unittest.TestCase): """test attribute setting on directories""" dname = self._getdir() self._checkListSetGet(dname) + self._checkListSetGet(dname, use_ns=True) def testSymlinkOpsDeprecated(self): """test symlink operations (deprecated functions)""" @@ -215,6 +267,7 @@ class xattrTest(unittest.TestCase): sname = self._getsymlink() self.failUnlessRaises(EnvironmentError, xattr.list, sname) self._checkListSetGet(sname, symlink=True) + self._checkListSetGet(sname, symlink=True, use_ns=True) def testBinaryPayloadDeprecated(self): """test binary values (deprecated functions)""" @@ -234,8 +287,14 @@ class xattrTest(unittest.TestCase): BINVAL = "abc" + '\0' + "def" xattr.set(fname, self.USER_ATTR, BINVAL) self.failUnlessEqual(xattr.list(fname), [self.USER_ATTR]) + self.failUnlessEqual(xattr.list(fname, namespace=NS_USER), + [self.USER_NN]) self.failUnlessEqual(xattr.get(fname, self.USER_ATTR), BINVAL) + self.failUnlessEqual(xattr.get(fname, self.USER_NN, + namespace=NS_USER), BINVAL) self.failUnlessEqual(xattr.get_all(fname), [(self.USER_ATTR, BINVAL)]) + self.failUnlessEqual(xattr.get_all(fname, namespace=NS_USER), + [(self.USER_NN, BINVAL)]) xattr.remove(fname, self.USER_ATTR) def testManyOpsDeprecated(self): @@ -257,11 +316,18 @@ class xattrTest(unittest.TestCase): fh, fname = self._getfile() xattr.set(fh, self.USER_ATTR, self.USER_VAL) VL = [self.USER_ATTR] + VN = [self.USER_NN] for i in range(self.MANYOPS_COUNT): self.failUnlessEqual(xattr.list(fh), VL) + self.failUnlessEqual(xattr.list(fh, namespace=NS_USER), VN) for i in range(self.MANYOPS_COUNT): self.failUnlessEqual(xattr.get(fh, self.USER_ATTR), self.USER_VAL) + self.failUnlessEqual(xattr.get(fh, self.USER_NN, + namespace=NS_USER), + self.USER_VAL) for i in range(self.MANYOPS_COUNT): self.failUnlessEqual(xattr.get_all(fh), [(self.USER_ATTR, self.USER_VAL)]) + self.failUnlessEqual(xattr.get_all(fh, namespace=NS_USER), + [(self.USER_NN, self.USER_VAL)]) -- 2.39.5