class TestFileSystemModule_MultipleMountFs(unittest.TestCase):

    def setUp(self):
        self.fsm = FilesystemModule()
        self.root_fs     = XJFileSystem(1024*1024*10)
        self.var_fs      = XJFileSystem(1024*1024*10)
        self.home_fs     = XJFileSystem(1024*1024*10)

        self.fsm.mount("/", self.root_fs)
        self.fsm.mount("/var", self.var_fs)
        self.fsm.mount("/home", self.home_fs)

    def test_when_mkdir_etc_then_directory_is_created_under_root_fs(self):
        self.fsm.mkdir("/etc",1,1,0777)
        self.assertTrue(self.root_fs.opendir('/').has_dir('etc'))
        self.assertFalse(self.var_fs.opendir('/').has_dir('etc'))

    def test_when_mkdir_var_log_then_it_is_created_under_var_fs(self):
        self.fsm.mkdir("/var/log",1,1,0777)
        self.assertFalse(self.root_fs.opendir('/').has_dir('log'))
        self.assertTrue(self.var_fs.opendir('/').has_dir('log'))

    def test_when_opendir_var_then_readdir_var_returns_dir_entries_for_root_dir_on_var_fs(self):
        self.fsm.mkdir("/var/log",1,1,0777)

        fd = self.fsm.opendir('/var')
        dentries = self.fsm.readdir(fd)

        self.assertTrue(dentries.has_key('log'))
        self.assertTrue(self.var_fs.opendir('/').has_dir('log'))
示例#2
0
class TestFileSystem(unittest.TestCase):

    def setUp(self):
        self.fsm = FilesystemModule()
        self.fsm.mount('/', XJFileSystem(1024*1024*10)) # 10 mb partition
        self.fs = Filesystem(self.fsm)
        self.fsm.creat('/prueba.txt', 1,1,0777)

    def test_when_file_exists_for_invalid_path_then_returns_false(self):
        self.assertFalse(self.fs.file_exists('/prueba'))

    def test_when_file_exists_for_valid_path_then_returns_true(self):
        self.assertTrue(self.fs.file_exists('/prueba.txt'))

    def test_when_put_file_binfile_then_binfile_exists(self):
        program = Program()
        program.set_name('binfile')
        self.fs.put_file('/binfile', program)
        self.assertTrue(self.fs.file_exists('/binfile'))

    def test_when_get_file_then_returns_file(self):
        program = Program()
        program.set_name('binfile')
        self.fs.put_file('/binfile', program)
        file = self.fs.get_file('/binfile')
        self.assertEqual(program,file)

    def test_when_mkpath_with_long_path_then_it_should_create_all_intermediate_directories(self):
        path = '/var/log/apache2/errors'
        self.fs.mkpath(path,1,1,0755)

        curr_path = '/'
        traversable_path = path.split('/')
        traversable_path.pop(0)
        for dir_name in traversable_path:
            fd = self.fsm.opendir(curr_path)
            dentries = self.fsm.readdir(fd)
            self.assertTrue(dentries.has_key(dir_name))
            self.fsm.close(fd)
            if curr_path != '/':
                sep = '/'
            else :
                sep = ''
            curr_path = curr_path + sep + dir_name
            print curr_path


    def test_when_list_file_then_returns_a_list_of_all_files_in_fs(self):
        self.fs.put_file('/root/.bashrc', 1)
        self.fs.put_file('/etc/apache/httpd.conf', 2)
        self.fs.put_file('/sbin/ifconfig', 3)