예제 #1
0
 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)
예제 #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)