summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-05-30 17:42:15 +0530
committerPrashanth Pai <ppai@redhat.com>2016-06-01 12:42:25 +0530
commit972c24f8b11d5a3e7e6fc341453d9733b2bb47b5 (patch)
treed38c5cdf723c1a029455147ddbb19cf126c3186e /test/unit
parent123c2b7dc51d012f6d2924f680eeec748187a300 (diff)
Implement os.utime() like API and zerofill
This patch: * Implements Volume.utime() which is very similar to os.utime() present in Python. https://docs.python.org/2/library/os.html#os.utime * Implements File.zerofill() which exposes glfs_zerofill. * Fixes function prototype of fallocate and discard. Adds functional tests for the same. Change-Id: Icb8d3a571998c31d6bf9b139ca253af59f6fc3f4 Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/gluster/test_gfapi.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py
index 84f6261..3934a6f 100644
--- a/test/unit/gluster/test_gfapi.py
+++ b/test/unit/gluster/test_gfapi.py
@@ -13,6 +13,8 @@ import unittest
import gluster
import os
import stat
+import time
+import math
import errno
from gluster.gfapi import File, Dir, Volume
@@ -997,3 +999,35 @@ class TestVolume(unittest.TestCase):
for (path, dirs, files) in self.vol.walk("dir1",
onerror=mock_onerror):
pass
+
+ def test_utime(self):
+ # Test times arg being invalid.
+ for junk in ('a', 1234.1234, (1, 2, 3), (1)):
+ self.assertRaises(TypeError, self.vol.utime, '/path', junk)
+
+ # Test times = None
+ mock_glfs_utimens = Mock(return_value=1)
+ mock_time = Mock(return_value=12345.6789)
+ with patch("gluster.gfapi.api.glfs_utimens", mock_glfs_utimens):
+ with patch("time.time", mock_time):
+ self.vol.utime('/path', None)
+ self.assertTrue(mock_glfs_utimens.called)
+ self.assertTrue(mock_time.called)
+
+ # Test times passed as arg
+ mock_glfs_utimens.reset_mock()
+ atime = time.time()
+ mtime = time.time()
+ with patch("gluster.gfapi.api.glfs_utimens", mock_glfs_utimens):
+ self.vol.utime('/path', (atime, mtime))
+ self.assertTrue(mock_glfs_utimens.called)
+ self.assertEqual(mock_glfs_utimens.call_args[0][1], '/path')
+ # verify atime and mtime
+ self.assertEqual(mock_glfs_utimens.call_args[0][2][0].tv_sec,
+ int(atime))
+ self.assertEqual(mock_glfs_utimens.call_args[0][2][0].tv_nsec,
+ int(math.modf(atime)[0] * 1e9))
+ self.assertEqual(mock_glfs_utimens.call_args[0][2][1].tv_sec,
+ int(mtime))
+ self.assertEqual(mock_glfs_utimens.call_args[0][2][1].tv_nsec,
+ int(math.modf(mtime)[0] * 1e9))