Ejemplo n.º 1
0
    def testIsFunctions(self):
        """Test the Is? functionality."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/syslog',
                                              parent=self._os_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

        self.assertFalse(file_entry.IsRoot())
        self.assertFalse(file_entry.IsVirtual())
        self.assertTrue(file_entry.IsAllocated())

        self.assertFalse(file_entry.IsDevice())
        self.assertFalse(file_entry.IsDirectory())
        self.assertTrue(file_entry.IsFile())
        self.assertFalse(file_entry.IsLink())
        self.assertFalse(file_entry.IsPipe())
        self.assertFalse(file_entry.IsSocket())

        path_spec = tar_path_spec.TarPathSpec(location=u'/',
                                              parent=self._os_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

        self.assertTrue(file_entry.IsRoot())
        self.assertTrue(file_entry.IsVirtual())
        self.assertTrue(file_entry.IsAllocated())

        self.assertFalse(file_entry.IsDevice())
        self.assertTrue(file_entry.IsDirectory())
        self.assertFalse(file_entry.IsFile())
        self.assertFalse(file_entry.IsLink())
        self.assertFalse(file_entry.IsPipe())
        self.assertFalse(file_entry.IsSocket())
Ejemplo n.º 2
0
    def testFileEntryExistsByPathSpec(self):
        """Test the file entry exists by path specification functionality."""
        file_system = tar_file_system.TarFileSystem(self._resolver_context)
        self.assertNotEqual(file_system, None)

        file_system.Open(path_spec=self._tar_path_spec)

        path_spec = tar_path_spec.TarPathSpec(location=u'/syslog',
                                              parent=self._os_path_spec)
        self.assertTrue(file_system.FileEntryExistsByPathSpec(path_spec))

        path_spec = tar_path_spec.TarPathSpec(location=u'/bogus',
                                              parent=self._os_path_spec)
        self.assertFalse(file_system.FileEntryExistsByPathSpec(path_spec))

        file_system.Close()
Ejemplo n.º 3
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._resolver_context = context.Context()
     test_file = os.path.join(u'test_data', u'syslog.tar')
     self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
     self._tar_path_spec = tar_path_spec.TarPathSpec(
         location=u'/syslog', parent=self._os_path_spec)
Ejemplo n.º 4
0
    def testInitialize(self):
        """Tests the path specification initialization."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/test',
                                              parent=self._path_spec)

        self.assertNotEqual(path_spec, None)

        with self.assertRaises(ValueError):
            _ = tar_path_spec.TarPathSpec(location=u'/test', parent=None)

        with self.assertRaises(ValueError):
            _ = tar_path_spec.TarPathSpec(location=None,
                                          parent=self._path_spec)

        with self.assertRaises(ValueError):
            _ = tar_path_spec.TarPathSpec(location=u'/test',
                                          parent=self._path_spec,
                                          bogus=u'BOGUS')
Ejemplo n.º 5
0
    def GetRootFileEntry(self):
        """Retrieves the root file entry.

    Returns:
      A file entry (instance of vfs.FileEntry).
    """
        path_spec = tar_path_spec.TarPathSpec(location=self.LOCATION_ROOT,
                                              parent=self._path_spec.parent)
        return self.GetFileEntryByPathSpec(path_spec)
Ejemplo n.º 6
0
    def testGetStat(self):
        """Test the get stat functionality."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/syslog',
                                              parent=self._os_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

        stat_object = file_entry.GetStat()

        self.assertNotEqual(stat_object, None)
        self.assertEqual(stat_object.type, stat_object.TYPE_FILE)
Ejemplo n.º 7
0
    def testComparable(self):
        """Tests the path specification comparable property."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/test',
                                              parent=self._path_spec)

        self.assertNotEqual(path_spec, None)

        expected_comparable = u'\n'.join(
            [u'type: TEST', u'type: TAR, location: /test', u''])

        self.assertEqual(path_spec.comparable, expected_comparable)
Ejemplo n.º 8
0
    def testGetFileEntryByPathSpec(self):
        """Test the get entry by path specification functionality."""
        file_system = tar_file_system.TarFileSystem(self._resolver_context)
        self.assertNotEqual(file_system, None)

        file_system.Open(path_spec=self._tar_path_spec)

        path_spec = tar_path_spec.TarPathSpec(location=u'/syslog',
                                              parent=self._os_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertNotEqual(file_entry, None)
        self.assertEqual(file_entry.name, u'syslog')

        path_spec = tar_path_spec.TarPathSpec(location=u'/bogus',
                                              parent=self._os_path_spec)
        file_entry = file_system.GetFileEntryByPathSpec(path_spec)

        self.assertEqual(file_entry, None)

        file_system.Close()
Ejemplo n.º 9
0
    def testGetParentFileEntry(self):
        """Test the get parent file entry functionality."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/syslog',
                                              parent=self._os_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

        self.assertNotEqual(file_entry, None)

        parent_file_entry = file_entry.GetParentFileEntry()

        self.assertNotEqual(parent_file_entry, None)

        self.assertEqual(parent_file_entry.name, u'')
Ejemplo n.º 10
0
    def testSubFileEntries(self):
        """Test the sub file entries iteration functionality."""
        path_spec = tar_path_spec.TarPathSpec(location=u'/',
                                              parent=self._os_path_spec)
        file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)

        self.assertNotEqual(file_entry, None)

        self.assertEqual(file_entry.number_of_sub_file_entries, 1)

        expected_sub_file_entry_names = [u'syslog']

        sub_file_entry_names = []
        for sub_file_entry in file_entry.sub_file_entries:
            sub_file_entry_names.append(sub_file_entry.name)

        self.assertEqual(len(sub_file_entry_names),
                         len(expected_sub_file_entry_names))
        self.assertEqual(sorted(sub_file_entry_names),
                         sorted(expected_sub_file_entry_names))