def testGetIdentity(self):
        # Test that file systems at different commits still have the same identity.
        other_gitiles_fs = GitilesFileSystem.Create(commit='abcdefghijklmnop')
        self.assertEqual(self._gitiles_fs.GetIdentity(),
                         other_gitiles_fs.GetIdentity())

        yet_another_gitiles_fs = GitilesFileSystem.Create(branch='different')
        self.assertNotEqual(self._gitiles_fs.GetIdentity(),
                            yet_another_gitiles_fs.GetIdentity())
Example #2
0
    def _CreateContentProvider(self, name, config):
        default_extensions = config.get('defaultExtensions', ())
        supports_templates = config.get('supportsTemplates', False)
        supports_zip = config.get('supportsZip', False)

        if 'chromium' in config:
            chromium_config = config['chromium']
            if 'dir' not in chromium_config:
                logging.error('%s: "chromium" must have a "dir" property' %
                              name)
                return None
            file_system = ChrootFileSystem(self._host_file_system,
                                           chromium_config['dir'])
        elif 'gitiles' in config:
            gitiles_config = config['gitiles']
            if 'dir' not in gitiles_config:
                logging.error('%s: "gitiles" must have a "dir" property' %
                              name)
                return None
            file_system = ChrootFileSystem(GitilesFileSystem.Create(),
                                           gitiles_config['dir'])
        elif 'gcs' in config:
            gcs_config = config['gcs']
            if 'bucket' not in gcs_config:
                logging.error('%s: "gcs" must have a "bucket" property' % name)
                return None
            bucket = gcs_config['bucket']
            if not bucket.startswith('gs://'):
                logging.error('%s: bucket %s should start with gs://' %
                              (name, bucket))
                return None
            bucket = bucket[len('gs://'):]
            file_system = self._gcs_file_system_provider.Create(bucket)
            if 'dir' in gcs_config:
                file_system = ChrootFileSystem(file_system, gcs_config['dir'])

        elif 'github' in config:
            github_config = config['github']
            if 'owner' not in github_config or 'repo' not in github_config:
                logging.error(
                    '%s: "github" must provide an "owner" and "repo"' % name)
                return None
            file_system = self._github_file_system_provider.Create(
                github_config['owner'], github_config['repo'])
            if 'dir' in github_config:
                file_system = ChrootFileSystem(file_system,
                                               github_config['dir'])

        else:
            logging.error('%s: content provider type not supported' % name)
            return None

        return ContentProvider(name,
                               self._compiled_fs_factory,
                               file_system,
                               self._object_store_creator,
                               default_extensions=default_extensions,
                               supports_templates=supports_templates,
                               supports_zip=supports_zip)
Example #3
0
 def _Create(self, branch, commit=None):
     '''Creates Gitiles file systems (or if in a test, potentially whatever
 |self._constructor_for_test specifies). Wraps the resulting file system in
 an Offline file system if the offline flag is set, and finally wraps it in
 a Caching file system.
 '''
     if self._constructor_for_test is not None:
         file_system = self._constructor_for_test(branch=branch,
                                                  commit=commit)
     else:
         file_system = GitilesFileSystem.Create(branch=branch,
                                                commit=commit)
     if self._offline:
         file_system = OfflineFileSystem(file_system)
     return CachingFileSystem(file_system, self._object_store_creator)
 def setUp(self):
     fetcher = _FakeGitilesFetcher(TestFileSystem(_TEST_FS))
     self._gitiles_fs = GitilesFileSystem(fetcher, _BASE_URL, 'master',
                                          None)
class GitilesFileSystemTest(unittest.TestCase):
    def setUp(self):
        fetcher = _FakeGitilesFetcher(TestFileSystem(_TEST_FS))
        self._gitiles_fs = GitilesFileSystem(fetcher, _BASE_URL, 'master',
                                             None)

    def testParseGitilesJson(self):
        test_json = '\n'.join([')]}\'', json.dumps({'commit': 'blah'})])
        self.assertEqual(_ParseGitilesJson(test_json), {'commit': 'blah'})

    def testCreateStatInfo(self):
        test_json = '\n'.join([
            ')]}\'',
            json.dumps({
                'id':
                'some_long_string',
                'entries': [{
                    'mode': 33188,
                    'type': 'blob',
                    'id': 'long_id',
                    'name': '.gitignore'
                }, {
                    'mode': 33188,
                    'type': 'blob',
                    'id': 'another_long_id',
                    'name': 'PRESUBMIT.py'
                }, {
                    'mode': 33188,
                    'type': 'blob',
                    'id': 'yali',
                    'name': 'README'
                }]
            })
        ])
        expected_stat_info = StatInfo(
            'some_long_string', {
                '.gitignore': 'long_id',
                'PRESUBMIT.py': 'another_long_id',
                'README': 'yali'
            })
        self.assertEqual(_CreateStatInfo(test_json), expected_stat_info)

    def testRead(self):
        # Read a top-level file.
        f = self._gitiles_fs.Read(['test1.txt'])
        self.assertEqual(f.Get(), {'test1.txt': 'test1'})
        # Read a top-level directory.
        f = self._gitiles_fs.Read(['dir1/'])
        self.assertEqual(f.Get(), {'dir1/': sorted(['test2.txt', 'dir2/'])})
        # Read a nested file.
        f = self._gitiles_fs.Read(['dir1/test2.txt'])
        self.assertEqual(f.Get(), {'dir1/test2.txt': 'test2'})
        # Read a nested directory.
        f = self._gitiles_fs.Read(['dir1/dir2/'])
        self.assertEqual(f.Get(), {'dir1/dir2/': ['test3.txt']})
        # Read multiple paths.
        f = self._gitiles_fs.Read(['test1.txt', 'dir1/test2.txt'])
        self.assertEqual(f.Get(), {
            'test1.txt': 'test1',
            'dir1/test2.txt': 'test2'
        })
        # Test skip not found.
        f = self._gitiles_fs.Read(['fakefile'], skip_not_found=True)
        self.assertEqual(f.Get(), {})

    def testGetCommitID(self):
        self.assertEqual(self._gitiles_fs.GetCommitID().Get(), 'a_commit')

    def testStat(self):
        self.assertEqual(
            self._gitiles_fs.Stat(_REAL_DATA_DIR).version,
            'ec21e736a3f00db2c0580e3cf71d91951656caec')

    def testGetIdentity(self):
        # Test that file systems at different commits still have the same identity.
        other_gitiles_fs = GitilesFileSystem.Create(commit='abcdefghijklmnop')
        self.assertEqual(self._gitiles_fs.GetIdentity(),
                         other_gitiles_fs.GetIdentity())

        yet_another_gitiles_fs = GitilesFileSystem.Create(branch='different')
        self.assertNotEqual(self._gitiles_fs.GetIdentity(),
                            yet_another_gitiles_fs.GetIdentity())