aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/base-images/base-builder/detect_repo_test.py
diff options
context:
space:
mode:
authorGravatar Leo Neat <leosneat@gmail.com>2020-01-30 10:27:56 -0800
committerGravatar GitHub <noreply@github.com>2020-01-30 10:27:56 -0800
commit007226e5ccc2bc597bbcf1a92b0623c51d2af7ca (patch)
treef696c39893327604ffa0c5ac7f30ee8d9f42a71d /infra/base-images/base-builder/detect_repo_test.py
parent22ea026e30401a71e6dbbf468f91a982bf2382a9 (diff)
[infra] unit/integration test updates (#3300)
* Merging build_specified_commit.py and utils.py * undo dataflow change * Updating RepoManager tests * Updated detect_repo_tests * Build specified commit updated * Updated test_repos * updating bisector tests * formatting updates * Switch inversions * Rebase master
Diffstat (limited to 'infra/base-images/base-builder/detect_repo_test.py')
-rw-r--r--infra/base-images/base-builder/detect_repo_test.py95
1 files changed, 27 insertions, 68 deletions
diff --git a/infra/base-images/base-builder/detect_repo_test.py b/infra/base-images/base-builder/detect_repo_test.py
index b15bedc6..4886522a 100644
--- a/infra/base-images/base-builder/detect_repo_test.py
+++ b/infra/base-images/base-builder/detect_repo_test.py
@@ -13,8 +13,10 @@
# limitations under the License.
"""Test the functionality of the detect_repo module.
This will consist of the following functional test:
- 1. Determine if a OSS-Fuzz projects main repo can be accurately deduce
- from example commits.
+ 1. Determine if an OSS-Fuzz projects main repo can be detected from example
+ commits.
+ 2. Determine if an OSS-Fuzz project main repo can be detected from a
+ repo name.
"""
import os
import re
@@ -30,96 +32,53 @@ sys.path.append(
os.path.dirname(os.path.dirname(os.path.dirname(
os.path.abspath(__file__)))))
import repo_manager
+import test_repos
# pylint: enable=wrong-import-position
-class DetectRepoTest(unittest.TestCase):
+class DetectRepoIntegrationTest(unittest.TestCase):
"""Class to test the functionality of the detect_repo module."""
- def test_infer_main_repo(self):
+ def test_infer_main_repo_from_commit(self):
"""Tests that the main repo can be inferred based on an example commit."""
with tempfile.TemporaryDirectory() as tmp_dir:
-
# Construct example repo's to check for commits.
- repo_manager.RepoManager('https://github.com/curl/curl.git', tmp_dir)
- repo_manager.RepoManager('https://github.com/weinrank/usrsctp', tmp_dir)
- repo_manager.RepoManager('https://github.com/ntop/nDPI.git', tmp_dir)
- repo_manager.RepoManager('https://github.com/libarchive/libarchive.git',
- tmp_dir)
-
- self.check_commit_with_repo('https://github.com/curl/curl.git', 'curl',
- 'bc5d22c3dede2f04870c37aec9a50474c4b888ad',
- tmp_dir)
-
- self.check_commit_with_repo('https://github.com/weinrank/usrsctp',
- 'usrsctp',
- '4886aaa49fb90e479226fcfc3241d74208908232',
- tmp_dir)
- self.check_commit_with_repo('https://github.com/ntop/nDPI.git', 'nDPI',
- 'c4d476cc583a2ef1e9814134efa4fbf484564ed7',
- tmp_dir)
- self.check_commit_with_repo(
- 'https://github.com/libarchive/libarchive.git', 'libarchive',
- '458e49358f17ec58d65ab1c45cf299baaf3c98d1', tmp_dir)
- self.check_commit_with_repo(None, None,
- 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', tmp_dir)
+ for example_repo in test_repos.TEST_REPOS:
+ repo_manager.RepoManager(example_repo.git_url, tmp_dir)
+ self.check_with_repo(example_repo.git_url,
+ example_repo.git_repo_name,
+ tmp_dir,
+ commit=example_repo.old_commit)
def test_infer_main_repo_from_name(self):
"""Tests that the main project repo can be inferred from a repo name."""
with tempfile.TemporaryDirectory() as tmp_dir:
- # Construct example repos to check for name.
- repo_manager.RepoManager('https://github.com/curl/curl.git', tmp_dir)
- repo_manager.RepoManager('https://github.com/ntop/nDPI.git', tmp_dir)
- repo_manager.RepoManager('https://github.com/libarchive/libarchive.git',
- tmp_dir)
- self.check_ref_with_repo('https://github.com/curl/curl.git', 'curl',
- tmp_dir)
- self.check_ref_with_repo('https://github.com/ntop/nDPI.git', 'nDPI',
- tmp_dir)
- self.check_ref_with_repo('https://github.com/libarchive/libarchive.git',
- 'libarchive', tmp_dir)
+ for example_repo in test_repos.TEST_REPOS:
+ repo_manager.RepoManager(example_repo.git_url, tmp_dir)
+ self.check_with_repo(example_repo.git_url, example_repo.git_repo_name,
+ tmp_dir)
- def check_ref_with_repo(self, repo_origin, repo_name, tmp_dir):
+ def check_with_repo(self, repo_origin, repo_name, tmp_dir, commit=None):
"""Checks the detect repo's main method for a specific set of inputs.
- Args:
- repo_origin: URL of the git repo.
- repo_name: The name of the directory it is cloned to.
- tmp_dir: The location of the directory of git repos to be searched.
- """
- command = [
- 'python3', 'detect_repo.py', '--src_dir', tmp_dir, '--repo_name',
- repo_name
- ]
- out, _ = detect_repo.execute(command,
- location=os.path.dirname(
- os.path.realpath(__file__)))
- match = re.search(r'\bDetected repo: ([^ ]+) ([^ ]+)', out.rstrip())
- if match and match.group(1) and match.group(2):
- self.assertEqual(match.group(1), repo_origin)
- self.assertEqual(match.group(2), os.path.join(tmp_dir, repo_name))
- else:
- self.assertIsNone(repo_origin)
- self.assertIsNone(repo_name)
-
- def check_commit_with_repo(self, repo_origin, repo_name, commit, tmp_dir):
- """Checks the detect repos main method for a specific set of inputs.
-
Args:
repo_origin: URL of the git repo.
repo_name: The name of the directory it is cloned to.
- commit: The commit that should be used to look up the repo.
tmp_dir: The location of the directory of git repos to be searched.
+ commit: The commit that should be used to look up the repo.
"""
- command = [
- 'python3', 'detect_repo.py', '--src_dir', tmp_dir, '--example_commit',
- commit
- ]
+ command = ['python3', 'detect_repo.py', '--src_dir', tmp_dir]
+
+ if commit:
+ command += ['--example_commit', commit]
+ else:
+ command += ['--repo_name', repo_name]
+
out, _ = detect_repo.execute(command,
location=os.path.dirname(
- os.path.abspath(__file__)))
+ os.path.realpath(__file__)))
match = re.search(r'\bDetected repo: ([^ ]+) ([^ ]+)', out.rstrip())
if match and match.group(1) and match.group(2):
self.assertEqual(match.group(1), repo_origin)