Added test for magic directories.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 19 Feb 2014 20:29:30 +0000 (15:29 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 19 Feb 2014 20:29:30 +0000 (15:29 -0500)
sdk/python/test_mount.py

index c361de22276aa5c006fa406bc0d3488065fd5f08..ce615984ed326d56f9c6b7b4143742cd7215b827 100644 (file)
@@ -89,6 +89,61 @@ class FuseMountTest(unittest.TestCase):
                 self.assertEqual(f.read(), v)
         
 
+    def tearDown(self):
+        # llfuse.close is buggy, so use fusermount instead.
+        #llfuse.close(unmount=True)
+        subprocess.call(["fusermount", "-u", self.mounttmp])
+
+        os.rmdir(self.mounttmp)
+        shutil.rmtree(self.keeptmp)
+
+class FuseMagicTest(unittest.TestCase):
+    def setUp(self):
+        self.keeptmp = tempfile.mkdtemp()
+        os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
+
+        cw = arvados.CollectionWriter()
+
+        cw.start_new_file('thing1.txt')
+        cw.write("data 1")
+
+        self.testcollection = cw.finish()
+
+    def runTest(self):
+        # Create the request handler
+        operations = fuse.Operations(os.getuid(), os.getgid())
+        e = operations.inodes.add_entry(fuse.MagicDirectory(llfuse.ROOT_INODE, operations.inodes))
+
+        self.mounttmp = tempfile.mkdtemp()
+
+        llfuse.init(operations, self.mounttmp, [])
+        t = threading.Thread(None, lambda: llfuse.main())
+        t.start()
+
+        # wait until the driver is finished initializing
+        operations.initlock.wait()
+
+        # now check some stuff
+        d1 = os.listdir(self.mounttmp)
+        d1.sort()
+        self.assertEqual(d1, [])
+
+        d2 = os.listdir(os.path.join(self.mounttmp, self.testcollection))
+        d2.sort()
+        self.assertEqual(d2, ['thing1.txt'])
+
+        d3 = os.listdir(self.mounttmp)
+        d3.sort()
+        self.assertEqual(d3, [self.testcollection])
+        
+        files = {}
+        files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
+
+        for k, v in files.items():
+            with open(os.path.join(self.mounttmp, k)) as f:
+                self.assertEqual(f.read(), v)
+        
+
     def tearDown(self):
         # llfuse.close is buggy, so use fusermount instead.
         #llfuse.close(unmount=True)