From 88bc71ff92026d889125bc0c4b14b450e41e62c4 Mon Sep 17 00:00:00 2001 From: Thiago da Silva Date: Sat, 12 Apr 2014 12:40:44 -0400 Subject: Added option to read whole file Added option to read whole file if caller send -1 as the buflen to read function. Also added a copy of getsize to File class, now called fgetsize, which returns the size of the file as reported by fstat Removed flags paramater from read function as it is never used by libgfapi. Change-Id: Ia1c04ef9717d9ca098e1961300d6ee216381c989 Signed-off-by: Thiago da Silva Signed-off-by: Prashanth Pai --- test/unit/gluster/test_gfapi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/unit') diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py index 1608332..0d73a32 100644 --- a/test/unit/gluster/test_gfapi.py +++ b/test/unit/gluster/test_gfapi.py @@ -180,6 +180,18 @@ class TestFile(unittest.TestCase): b = self.fd.read(5) self.assertEqual(b, 0) + def test_read_buflen_negative(self): + _mock_fgetsize = Mock(return_value=12345) + + def _mock_glfs_read(fd, rbuf, buflen, flags): + self.assertEqual(buflen, 12345) + return buflen + + for buflen in (-1,-2,-999): + with patch("glusterfs.gfapi.api.glfs_read", _mock_glfs_read): + with patch("glusterfs.gfapi.File.fgetsize", _mock_fgetsize): + b = self.fd.read(buflen) + def test_write_success(self): mock_glfs_write = Mock() mock_glfs_write.return_value = 5 -- cgit