]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add test for get_pathinfo()
authorRamakrishnan Muthukrishnan <ram@leastauthority.com>
Wed, 12 Aug 2015 08:43:13 +0000 (14:13 +0530)
committerDaira Hopwood <daira@jacaranda.org>
Wed, 30 Sep 2015 15:45:25 +0000 (16:45 +0100)
src/allmydata/test/test_util.py

index 8cca7b5e71b258a5ef5726c6d3b7d070eb2a9238..a2fa3b898d5df5a20757008569c54e8155937350 100644 (file)
@@ -634,6 +634,32 @@ class FileUtil(ReallyEqualMixin, unittest.TestCase):
         disk = fileutil.get_disk_stats('.', 2**128)
         self.failUnlessEqual(disk['avail'], 0)
 
+    def test_get_pathinfo(self):
+        basedir = "util/FileUtil/test_get_pathinfo"
+        fileutil.make_dirs(basedir)
+        d = os.path.join(basedir, "foobar")
+
+        # create a directory
+        self.mkdir(d, "a")
+        dirinfo = fileutil.get_pathinfo(d)
+        self.failUnlessTrue(dirinfo.isdir)
+        self.failUnlessTrue(dirinfo.exists)
+
+        # create a file under the directory
+        f = os.path.join(d, "a/1.txt")
+        self.touch(d, "a/1.txt", data="a"*10)
+        fileinfo = fileutil.get_pathinfo(f)
+        self.failUnlessTrue(fileinfo.isfile)
+        self.failUnlessTrue(fileinfo.exists)
+        self.failUnlessEqual(fileinfo.size, 10)
+
+        # create a simlink under the directory a pointing to 1.txt
+        slname = os.path.join(d, "a/linkto1.txt")
+        os.symlink(f, slname)
+        symlinkinfo = fileutil.get_pathinfo(slname)
+        self.failUnlessTrue(symlinkinfo.islink)
+        self.failUnlessTrue(symlinkinfo.exists)
+
 
 class PollMixinTests(unittest.TestCase):
     def setUp(self):