示例#1
0
    def next(self):
        entry = api.Dirent()
        entry.d_reclen = 256
        rc = api.glfs_readdir_r(self.fd, ctypes.byref(entry),
                                ctypes.byref(self.cursor))

        if (rc < 0) or (not self.cursor) or (not self.cursor.contents):
            return rc

        return entry
    def test_listdir_success(self):
        mock_glfs_opendir = Mock()
        mock_glfs_opendir.return_value = 2

        dirent1 = api.Dirent()
        dirent1.d_name = "mockfile"
        dirent1.d_reclen = 8
        dirent2 = api.Dirent()
        dirent2.d_name = "mockdir"
        dirent2.d_reclen = 7
        dirent3 = api.Dirent()
        dirent3.d_name = "."
        dirent3.d_reclen = 1
        mock_Dir_next = Mock()
        mock_Dir_next.side_effect = [dirent1, dirent2, dirent3, None]

        with nested(patch("gluster.gfapi.api.glfs_opendir", mock_glfs_opendir),
                    patch("gluster.gfapi.Dir.next", mock_Dir_next)):
            d = self.vol.listdir("testdir")
            self.assertEqual(len(d), 2)
            self.assertEqual(d[0], 'mockfile')