From bd683d93cb8d967f761d53f7a6b4243eb8eaedea Mon Sep 17 00:00:00 2001 From: Thiago da Silva Date: Wed, 26 Mar 2014 16:31:28 -0400 Subject: adding new apis requested from gluster-swift proj This patch adds new functions that are used in gluster-swift. These functions are: dup, lseek, getatime, getctime, getmtime Change-Id: I09036f7e393a89e09913f7f6de173e1eca8dca95 Signed-off-by: Thiago da Silva --- test/functional/libgfapi-python-tests.py | 24 ++++++++++++++++++++++++ test/unit/gluster/test_gfapi.py | 20 +++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index ac5c38f..baad035 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -78,6 +78,7 @@ class FileOpsTest(unittest.TestCase): self.assertEqual(rc, len(self.data)) ret = fd.fsync() self.assertEqual(ret, 0) + self.assertEqual(fd.originalpath, self.path) def tearDown(self): self.path = None @@ -110,6 +111,29 @@ class FileOpsTest(unittest.TestCase): g.close() self.fail("Expected a OSError with errno.EEXIST") + def test_write_file_dup_lseek_read(self): + try: + f = self.vol.open("dune", os.O_CREAT | os.O_EXCL | os.O_RDWR) + f.write("I must not fear. Fear is the mind-killer.") + fdup = f.dup() + self.assertTrue(isinstance(fdup, gfapi.File)) + f.close() + ret = fdup.lseek(0, os.SEEK_SET) + self.assertEqual(ret, 0) + + buf = fdup.read(15) + self.assertEqual(buf.value, "I must not fear") + + ret = fdup.lseek(29, os.SEEK_SET) + self.assertEqual(ret, 29) + + buf = fdup.read(11) + self.assertEqual(buf.value, "mind-killer") + + fdup.close() + except OSError as e: + self.fail(e.message) + def test_exists(self): e = self.vol.exists(self.path) self.assertTrue(e) diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py index ed7ed45..e0308f7 100644 --- a/test/unit/gluster/test_gfapi.py +++ b/test/unit/gluster/test_gfapi.py @@ -49,7 +49,7 @@ class TestFile(unittest.TestCase): @classmethod def setUpClass(cls): - cls.fd = gfapi.File(2) + cls.fd = gfapi.File(2, 'fakefile') @classmethod def tearDownClass(cls): @@ -77,6 +77,16 @@ class TestFile(unittest.TestCase): with patch("glusterfs.gfapi.api.glfs_fchown", mock_glfs_fchown): self.assertRaises(OSError, self.fd.fchown, 9, 11) + def test_dup(self): + mock_glfs_dup = Mock() + mock_glfs_dup.return_value = 2 + + with patch("glusterfs.gfapi.api.glfs_dup", mock_glfs_dup): + f = self.fd.dup() + self.assertTrue(isinstance(f, gfapi.File)) + self.assertEqual(f.originalpath, "fakefile") + self.assertEqual(f.fd, 2) + def test_fdatasync_success(self): mock_glfs_fdatasync = Mock() mock_glfs_fdatasync.return_value = 4 @@ -122,6 +132,14 @@ class TestFile(unittest.TestCase): with patch("glusterfs.gfapi.api.glfs_fsync", mock_glfs_fsync): self.assertRaises(OSError, self.fd.fsync) + def test_lseek_success(self): + mock_glfs_lseek = Mock() + mock_glfs_lseek.return_value = 20 + + with patch("glusterfs.gfapi.api.glfs_lseek", mock_glfs_lseek): + o = self.fd.lseek(20, os.SEEK_SET) + self.assertEqual(o, 20) + def test_read_success(self): def _mock_glfs_read(fd, rbuf, buflen, flags): rbuf.value = "hello" -- cgit