From: Felipe Barriga Richards Date: Mon, 27 Feb 2017 01:20:24 +0000 (-0300) Subject: tests.py: Added more tests. X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=2d95c9ab430c4f193958d271115a9f0a78c9e1ef;p=rrq%2Ffuse_xattrs.git tests.py: Added more tests. --- diff --git a/test/tests.py b/test/tests.py index 48a10f3..51e7b1e 100755 --- a/test/tests.py +++ b/test/tests.py @@ -22,17 +22,30 @@ import os class TestXAttrs(unittest.TestCase): def setUp(self): - self.randomFile = "./mount/foo.txt" - self.randomFileSidecar = "./mount/foo.txt.xattr" + self.sourceDir = "./source/" + self.mountDir = "./mount/" + self.randomFilename = "foo.txt" + + self.randomFile = self.mountDir + self.randomFilename + self.randomFileSidecar = self.randomFile + ".xattr" + + self.randomSourceFile = self.sourceDir + self.randomFilename + self.randomSourceFileSidecar = self.randomSourceFile + ".xattr" + if os.path.isfile(self.randomFile): os.remove(self.randomFile) - Path(self.randomFile).touch() if os.path.isfile(self.randomFileSidecar): os.remove(self.randomFileSidecar) + Path(self.randomFile).touch() + self.assertTrue(os.path.isfile(self.randomFile)) + self.assertFalse(os.path.isfile(self.randomFileSidecar)) + def tearDown(self): - os.remove(self.randomFile) + if os.path.isfile(self.randomFile): + os.remove(self.randomFile) + if os.path.isfile(self.randomFileSidecar): os.remove(self.randomFileSidecar) @@ -213,6 +226,51 @@ class TestXAttrs(unittest.TestCase): self.assertEqual(ex.exception.errno, 61) self.assertEqual(ex.exception.strerror, "No data available") + def test_hide_sidecar(self): + xattr.setxattr(self.randomFile, "user.foo", bytes("bar", "utf-8")) + self.assertTrue(os.path.isfile(self.randomFile)) + self.assertFalse(os.path.isfile(self.randomFileSidecar)) + + sidecarFilename = self.randomFilename + ".xattr" + files_mount = os.listdir(self.mountDir) + self.assertTrue(self.randomFilename in files_mount) + self.assertTrue(sidecarFilename not in files_mount) + + files_source = os.listdir(self.sourceDir) + self.assertTrue(self.randomFilename in files_source) + self.assertTrue(sidecarFilename in files_source) + + def test_create_new_file(self): + test_filename = "test_create_new_file" + self.assertFalse(os.path.isfile(self.sourceDir + test_filename)) + self.assertFalse(os.path.isfile(self.mountDir + test_filename)) + + open(self.mountDir + test_filename, "a").close() + self.assertTrue(os.path.isfile(self.sourceDir + test_filename)) + self.assertTrue(os.path.isfile(self.mountDir + test_filename)) + # FIXME: if one assert fails, the file isn't going to be deleted + os.remove(self.mountDir + test_filename) + + def test_remove_file_with_sidecar(self): + xattr.setxattr(self.randomFile, "user.foo", bytes("bar", "utf-8")) + self.assertTrue(os.path.isfile(self.randomFile)) + self.assertTrue(os.path.isfile(self.randomSourceFile)) + self.assertTrue(os.path.isfile(self.randomSourceFileSidecar)) + + os.remove(self.randomFile) + self.assertFalse(os.path.isfile(self.randomFile)) + self.assertFalse(os.path.isfile(self.randomSourceFile)) + self.assertFalse(os.path.isfile(self.randomSourceFileSidecar)) + + def test_remove_file_without_sidecar(self): + self.assertTrue(os.path.isfile(self.randomFile)) + self.assertTrue(os.path.isfile(self.randomSourceFile)) + self.assertFalse(os.path.isfile(self.randomSourceFileSidecar)) + + os.remove(self.randomFile) + self.assertFalse(os.path.isfile(self.randomFile)) + self.assertFalse(os.path.isfile(self.randomSourceFile)) + self.assertFalse(os.path.isfile(self.randomSourceFileSidecar)) if __name__ == '__main__': unittest.main()