def test_repositories_added_can_be_scanned(self, mock_rootdir, repo_to_scan): directory = '{}/repos/{}'.format( mock_rootdir, BaseStorage.hash_filename('Yelp/detect-secrets'), ) mocked_sha = 'aabbcc' # We don't **actually** want to clone the repo per test run. with mock_git_calls( SubprocessMock(expected_input=( 'git clone https://github.com/Yelp/detect-secrets {} --bare' ).format(directory, ), ), # Since there is no prior sha to retrieve SubprocessMock( expected_input='git rev-parse HEAD', mocked_output=mocked_sha, )): assert main([ 'add', 'https://github.com/Yelp/detect-secrets', '--root-dir', mock_rootdir, ]) == 0 with mock_git_calls( # Getting latest changes SubprocessMock( expected_input='git rev-parse --abbrev-ref HEAD', mocked_output='master', ), SubprocessMock( expected_input= 'git fetch --quiet origin master:master --force', ), # Getting relevant diff SubprocessMock( expected_input= 'git diff {} HEAD --name-only --diff-filter ACM'.format( mocked_sha), mocked_output='filenameA', ), SubprocessMock( expected_input='git diff {} HEAD -- filenameA'.format( mocked_sha), mocked_output='', ), # Storing latest sha SubprocessMock(expected_input='git rev-parse HEAD', ), ): assert main([ 'scan', repo_to_scan, '--root-dir', mock_rootdir, ]) == 0
def add_non_local_repo(self, mock_rootdir): repo = '[email protected]:yelp/detect-secrets' directory = '{}/repos/{}'.format( mock_rootdir, BaseStorage.hash_filename('yelp/detect-secrets'), ) git_calls = [ SubprocessMock(expected_input='git clone {} {} --bare'.format( repo, directory), ), SubprocessMock( expected_input='git rev-parse HEAD', mocked_output='mocked_sha', ), ] with mock_git_calls(*git_calls): args = self.parse_args('add {} --root-dir {}'.format( repo, mock_rootdir)) add_repo(args)