diff options
author | Leo Neat <leosneat@gmail.com> | 2019-12-12 09:26:37 -0800 |
---|---|---|
committer | Max Moroz <mmoroz@chromium.org> | 2019-12-12 09:26:37 -0800 |
commit | 2dd2a0fdccd3817c2f8766199140b4e088c7e0d2 (patch) | |
tree | 7781adac0aedc471866e5d7cdf8cb4c812627076 /infra/repo_manager_test.py | |
parent | 0d226427c7695564549d394fdb5f24d1dc6bf4d5 (diff) | |
download | oss-fuzz-2dd2a0fdccd3817c2f8766199140b4e088c7e0d2.tar.gz |
[infra] Add functionality to check out a specific commit for a project (#3092)
* Starting the git python API
* repo manager working with tests
* Docker repo manager working, can update image with specific commit
* Working bisection
* Formatting and linting
* Working bisection
* Specific commit checkout
* Specific commit checkout
* Removed bisector and updated helper
* remove branch bug
* Max comments
* Added tests for infer main repo
* Oliver comments
* helper.py function names change
* Oliver comments pt. 2
* Olivers comments
* Formatting updates
* Removing DockerRepoManager class
* Removing DockerRepoManager class
* Changing from copying repo to docker image to mounting repo on docker image
* Jonathan comments
* Build image from commit tests
* Oliver comments pt.3
* Oliver comments pt.4
* Linting
* Max comments pt. 2
* change check commit exists
* Max comments pt. 3
* Regex updated
* Formatting updates
Diffstat (limited to 'infra/repo_manager_test.py')
-rw-r--r-- | infra/repo_manager_test.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/infra/repo_manager_test.py b/infra/repo_manager_test.py new file mode 100644 index 000000000..b5e5b151a --- /dev/null +++ b/infra/repo_manager_test.py @@ -0,0 +1,78 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing perepo_managerissions and +# limitations under the License. +"""Test the functionality of the RepoManager class +The will consist of the following functional tests + 1. Cloning of directory in desired location + 2. Checking out a specific commit + 3. Can get a list of commits between two SHAs +""" + +import os +import unittest + +from RepoManager import RepoManager +from RepoManager import RepoManagerError + + +class TestRepoManager(unittest.TestCase): + """Class to test the functionality of the RepoManager class.""" + + curl_repo = 'https://github.com/curl/curl' + + def test_clone_correctly(self): + """Tests the correct location of the git repo.""" + repo_manager = RepoManager(self.curl_repo, 'tmp') + git_path = os.path.join(repo_manager.base_dir, repo_manager.repo_name, + '.git') + self.assertTrue(os.path.isdir(git_path)) + repo_manager.remove_repo() + with self.assertRaises(RepoManagerError): + repo_manager = RepoManager(' ', 'tmp') + + def test_checkout_commit(self): + """Tests that the git checkout command works.""" + repo_manager = RepoManager(self.curl_repo, 'tmp') + commit_to_test = '036ebac0134de3b72052a46f734e4ca81bb96055' + repo_manager.checkout_commit(commit_to_test) + self.assertEqual(commit_to_test, repo_manager.get_current_commit()) + with self.assertRaises(ValueError): + repo_manager.checkout_commit(' ') + with self.assertRaises(RepoManagerError): + repo_manager.checkout_commit('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') + repo_manager.remove_repo() + + def test_get_commit_list(self): + """Tests an accurate commit list can be retrived from the repo manager.""" + repo_manager = RepoManager(self.curl_repo, 'tmp') + old_commit = '7cf18b05e04bbb0f08c74d2567b0648f6c31a952' + new_commit = '113db127ee2b2f874dfcce406103ffe666e11953' + commit_list = [ + '113db127ee2b2f874dfcce406103ffe666e11953', + '793e37767581aec7102d2ecafa34fc1316b1b31f', + '9a2cbf30b81a2b57149bb20e78e2e4cb5c2ff389', + '7cf18b05e04bbb0f08c74d2567b0648f6c31a952' + ] + result_list = repo_manager.get_commit_list(old_commit, new_commit) + self.assertListEqual(commit_list, result_list) + with self.assertRaises(RepoManagerError): + repo_manager.get_commit_list('asafd', new_commit) + with self.assertRaises(RepoManagerError): + repo_manager.get_commit_list(new_commit, 'asdfasdf') + with self.assertRaises(RepoManagerError): + # Testing commits out of order + result_list = repo_manager.get_commit_list(new_commit, old_commit) + + +if __name__ == '__main__': + unittest.main() |