Exemple #1
0
 def test_bundle_all(self):
     """Tests bundling multiple real repositories. This uses an array of URLs that 
        represent smallish repositories that are unlikely to go away."""
     print("\ntest_bundle_all")
     repo_urls = [
         "https://github.com/octocat/Hello-World.git",
         "https://github.com/octocat/git-consortium",
         "https://bitbucket.org/atlassian_tutorial/helloworld.git",
         "https://github.com/Microsoft/api-guidelines",
     ]
     throttler = bundle_repos.Throttler(2.0)
     config = bundle_repos.BundleConfig()
     config.throttler = throttler
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, 'repositories')
         os.mkdir(bundles_dir)
         print("bundles dir: {}".format(bundles_dir))
         num_ok = bundle_repos.Bundler(bundles_dir, tmpdir,
                                       config=config).bundle_all(repo_urls)
         self.assertEqual(num_ok, len(repo_urls))
         bundle_files = tests.list_files_recursively(bundles_dir)
         print("bundle files: {}".format(bundle_files))
         self.assertEqual(len(bundle_files), len(repo_urls))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'octocat',
                           'Hello-World.git.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'octocat',
                           'git-consortium.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'Microsoft',
                           'api-guidelines.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'bitbucket.org',
                           'atlassian_tutorial', 'helloworld.git.bundle')))
Exemple #2
0
 def test_bundle_required(self):
     source_bundle_path = tests.get_data_dir('sample-repo-branched.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         old_metadata = os.stat(dest_bundle_path)
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         old_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             dest_bundle_path, tmpdir, bundler.git_runner)
         assert old_latest_commit == KNOWN_SAMPLE_REPO_LATEST_COMMIT_HASH
         new_bundle_path = bundler.bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             new_bundle_path, tmpdir, bundler.git_runner)
         self.assertEqual(
             new_latest_commit,
             KNOWN_SAMPLE_REPO_BRANCHED_LATEST_COMMIT_HASH,
             "latest commit hash from sample-repo-branched is incorrect")
         new_hash = tests.hash_file(new_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, old_metadata,
                             "metadata should have changed")
         self.assertNotEqual(new_hash, original_hash,
                             "hash should have changed")
Exemple #3
0
 def do_test_read_git_latest_commit(self, bundle_path, expected_hash):
     with tests.TemporaryDirectory() as tempdir:
         git = bundle_repos.GitRunner('git')
         clone_dir = os.path.join(tempdir, 'cloned-bundle-directory')
         git.clone_mirrored_clean(bundle_path, clone_dir)
         commit_hash = bundle_repos.read_git_latest_commit(clone_dir)
         self.assertEqual(commit_hash, expected_hash)
Exemple #4
0
 def test_cwd(self):
     with tests.TemporaryDirectory() as tempdir:
         runner = bundle_repos.GitRunner('pwd')
         proc = runner.run(['pwd'], cwd=tempdir)
         self.assertEqual(proc.returncode, 0)
         actual = proc.stdout.decode('utf8').strip()
         self.assertEqual(actual, tempdir)
Exemple #5
0
 def test_git_script_print_latest_commit(self):
     with tests.TemporaryDirectory() as tempdir:
         clone_dir = os.path.join(tempdir, 'cloned-dir')
         os.makedirs(clone_dir)
         proc = self.git_runner.run(
             bundle_repos._GIT_CMD_PRINT_LATEST_COMMIT, cwd=clone_dir)
         self.assertEqual(proc.returncode, 0)
         self.assertRegex(proc.stdout.decode('utf-8'), r'^[a-f0-9]{40}')
Exemple #6
0
 def test_git_script_clone(self):
     with tests.TemporaryDirectory() as tempdir:
         clone_dest = os.path.join(tempdir, 'clone-destination')
         proc = self.git_runner.run(
             ['git', 'clone', 'REMOTE_URL', clone_dest])
         print(proc.stdout.decode('utf-8'))
         print(proc.stderr.decode('utf-8'), file=sys.stderr)
         self.assertEqual(proc.returncode, 0)
Exemple #7
0
 def test_bundle_one(self):
     print("\ntest_bundle_one")
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, 'repositories')
         os.mkdir(bundles_dir)
         bundle_path = bundle_repos.Bundler(bundles_dir, tmpdir).bundle(
             Repository("https://github.com/octocat/Hello-World.git"))
         self.assertIsNotNone(bundle_path, "bundle returned None")
         self.assertBundleVerifies(bundle_path)
Exemple #8
0
 def test_bundle_from_bundle_source(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     assert os.path.isfile(source_bundle_path)
     repo = Repository(pathlib.Path(source_bundle_path).as_uri())
     with tests.TemporaryDirectory() as tmpdir:
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         bundle_path = bundler.bundle(repo)
         # not sure of an independent way to check that this bundle is correct
         self.assertIsNotNone(bundle_path, "bundle path is None")
         self.assertBundleVerifies(bundle_path)
Exemple #9
0
 def test_git_script_bundle(self):
     with tests.TemporaryDirectory() as tempdir:
         bundle_path = os.path.join(tempdir, 'my.bundle')
         proc = self.git_runner.run(
             ['git', 'bundle', 'create', bundle_path, "--all"])
         print(proc.stdout.decode('utf-8'))
         print(proc.stderr.decode('utf-8'), file=sys.stderr)
         self.assertEqual(proc.returncode, 0)
         self.assertTrue(os.path.isfile(bundle_path),
                         "bundle not created: " + bundle_path)
Exemple #10
0
 def test_clone_mirrored_clean(self):
     bundle_path = tests.get_data_dir('sample-repo-branched.bundle')
     with tests.TemporaryDirectory() as clone_dir:
         runner = bundle_repos.GitRunner('git')
         runner.clone_mirrored_clean(bundle_path, clone_dir)
         branch_list_lines = runner.run_clean(
             ['git', 'branch', '-l'],
             cwd=clone_dir).stdout.decode('utf-8').split("\n")
         branch_list_lines = list(filter(lambda x: x, branch_list_lines))
         branch_list = [b.strip().split()[-1] for b in branch_list_lines]
         self.assertSetEqual(set(branch_list), {'master', 'other-branch'})
Exemple #11
0
 def test_bundle(self):
     repo = Repository("https://localhost/hsolo/falcon.git")
     with tests.TemporaryDirectory() as treetop:
         bundle_name = self.make_bundler(treetop).bundle(repo)
         print("created {}".format(bundle_name))
         expected = os.path.join(treetop, 'localhost', 'hsolo',
                                 'falcon.git.bundle')
         self.assertEqual(bundle_name, expected)
         if not os.path.isfile(bundle_name):
             print("contents of directory {}".format(treetop),
                   file=sys.stderr)
             for f in tests.list_files_recursively(treetop):
                 print("  '{}'".format(f), file=sys.stderr)
         self.assertTrue(os.path.isfile(bundle_name),
                         "expected file to exist at " + bundle_name)
Exemple #12
0
 def test_bundle_all_throttling(self):
     repo_urls = [
         "https://github.com/octocat/Hello-World.git",
         "https://localhost/foo/bar.git",
         "https://bitbucket.org/atlassian_tutorial/helloworld.git",
         "https://github.com/Microsoft/api-guidelines",
     ]
     counter = CountingThrottler(0)
     config = bundle_repos.BundleConfig()
     config.throttler = counter
     with tests.TemporaryDirectory() as tmpdir:
         self.make_bundler(tmpdir, config).bundle_all(repo_urls)
     print("counts: {}".format(counter.counts))
     self.assertEqual(counter.counts['github.com'], 2)
     self.assertEqual(counter.counts['bitbucket.org'], 1)
     self.assertEqual(counter.counts['localhost'], 1)
Exemple #13
0
 def test_bundle_fail(self):
     """Tests bundling a repository that does not exist, causing a failure"""
     print("\ntest_bundle_fail")
     repo_urls = ["file:///path/to/nowhere.bundle"]
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, "repositories")
         os.mkdir(bundles_dir)
         num_ok = bundle_repos.Bundler(bundles_dir,
                                       tmpdir).bundle_all(repo_urls)
         self.assertEqual(0, num_ok, "num_ok")
         for url in repo_urls:
             potential_bundle_path = Repository(url).make_bundle_path(
                 bundles_dir)
             self.assertFalse(
                 os.path.exists(potential_bundle_path),
                 "file exists at {} but shouldn't".format(
                     potential_bundle_path))
Exemple #14
0
 def test_bundle_not_required_force(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         config = bundle_repos.BundleConfig(ignore_rev=True)
         new_bundle_path = bundle_repos.Bundler(tmpdir,
                                                tmpdir,
                                                config=config).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, original_metadata,
                             "file metadata should have changed")
Exemple #15
0
 def test_bundle_not_required_skip(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         new_bundle_path = bundle_repos.Bundler(tmpdir, tmpdir).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_hash = tests.hash_file(new_bundle_path)
         self.assertEqual(new_hash, original_hash,
                          "hash should NOT have changed")
         new_metadata = os.stat(new_bundle_path)
         self.assertEqual(new_metadata, original_metadata,
                          "file metadata should NOT have changed")
Exemple #16
0
 def do_test_read_git_latest_commit_from_bundle(self, bundle_path,
                                                expected_hash):
     with tests.TemporaryDirectory() as tempdir:
         commit_hash = bundle_repos.read_git_latest_commit_from_bundle(
             bundle_path, tempdir)
         self.assertEqual(commit_hash, expected_hash)