def test_can_detect_valid_urls_and_handle_invalid_ones(self) -> None: fixture = [ ( "[email protected]:seppeljordan/nix-prefetch-github.git", GithubRepository( owner="seppeljordan", name="nix-prefetch-github", ), ), ( "https://github.com/seppeljordan/nix-prefetch-github.git", GithubRepository( owner="seppeljordan", name="nix-prefetch-github", ), ), ( "invalid", None, ), ] for url, expected_repository in fixture: with self.subTest(): self.assertEqual( detect_github_repository_from_remote_url(url), expected_repository, )
def test_controller_extracts_alternative_owner_and_repo_from_arguments( self, ) -> None: expected_owner = "other_owner" expected_repo = "other_repo" self.controller.process_arguments([expected_owner, expected_repo]) self.assertRepository( GithubRepository(owner=expected_owner, name=expected_repo), )
def test_get_correct_reference_for_version_v2_3(self) -> None: repository = GithubRepository(owner="seppeljordan", name="nix-prefetch-github") remote_list = self.factory.get_list_remote(repository) assert remote_list self.assertEqual(remote_list.tag("v2.3"), "e632ce77435a4ab269c227c3ebcbaeaf746f8627")
def test_controller_can_handle_rendering_flag_in_front_of_arguments( self) -> None: expected_owner = "owner" expected_repo = "repo" self.controller.process_arguments( ["--nix", expected_owner, expected_repo]) self.assertRepository( GithubRepository(owner=expected_owner, name=expected_repo), )
def setUp(self) -> None: self.url_hasher = FakeUrlHasher() self.repository = GithubRepository( owner="sensu", name="sensu-go", ) self.revision_index_factory = FakeRevisionIndexFactory() self.prefetcher = PrefetcherImpl(self.url_hasher, self.revision_index_factory)
def setUp(self) -> None: self.hasher = NixBuildUrlHasherImpl(command_runner=CommandRunnerImpl( getLogger(__name__)), logger=getLogger()) self.repository = GithubRepository( owner="git-up", name="test-repo-submodules", ) self.revision = "5a1dfa807759c39e3df891b6b46dfb2cf776c6ef"
def _make_repository(self, leave_dot_git: bool = False, deep_clone: bool = False) -> PrefetchedRepository: return PrefetchedRepository( repository=GithubRepository(owner="test", name="test"), rev="test", sha256="test", options=PrefetchOptions(leave_dot_git=leave_dot_git, deep_clone=deep_clone), )
def get_list_remote(self, repository: GithubRepository) -> Optional[ListRemote]: repository_url = repository.url() returncode, output = self.command_runner.run_command( command=["git", "ls-remote", "--symref", repository_url], environment_variables={"GIT_ASKPASS": "", "GIT_TERMINAL_PROMPT": "0"}, merge_stderr=False, ) if returncode == 0: return ListRemote.from_git_ls_remote_output(output) else: return None
def main(args: Optional[List[str]] = None) -> None: injector = DependencyInjector() arguments = parse_arguments(args) logging_factory = injector.get_logger_factory() logging_factory.set_logging_configuration(arguments.logging_configuration) use_case = injector.get_prefetch_latest_release_use_case() use_case.prefetch_latest_release(request=Request( repository=GithubRepository(owner=arguments.owner, name=arguments.repo), prefetch_options=arguments.prefetch_options, rendering_format=arguments.rendering_format, ))
def detect_github_repository_from_remote_url( url: str) -> Optional[GithubRepository]: match = re.match("([email protected]:|https://github.com/)(.+)/(.+).git", url) if not match: return None else: owner = match.group(2) name = match.group(3) return GithubRepository( name=name, owner=owner, )
def process_arguments(self, arguments: List[str]) -> None: parser = argparse.ArgumentParser( "nix-prefetch-github", parents=[get_options_argument_parser()]) parser.add_argument("owner") parser.add_argument("repo") parser.add_argument("--rev", default=None) args = parser.parse_args(arguments) self._logger_manager.set_logging_configuration( args.logging_configuration) self._use_case.prefetch_github_repository(request=Request( repository=GithubRepository(owner=args.owner, name=args.repo), revision=args.rev, prefetch_options=args.prefetch_options, rendering_format=args.rendering_format, ))
def setUp(self) -> None: self.result_output = StringIO() self.error_output = StringIO() self.renderer = TestingRepositoryRenderer() self.presenter = PresenterImpl( result_output=self.result_output, error_output=self.error_output, repository_renderer=self.renderer, ) self.repo = PrefetchedRepository( GithubRepository(owner="test", name="test"), rev="test", sha256="test", options=PrefetchOptions(), )
def setUp(self) -> None: self.nix_build_hasher = FakeUrlHasher() self.nix_prefetch_hasher = FakeUrlHasher() self.availability_checker = FakeCommandAvailabilityChecker() self.selector = UrlHasherSelector( availability_checker=self.availability_checker, nix_build_implementation=self.nix_build_hasher, nix_prefetch_implementation=self.nix_prefetch_hasher, ) self.availability_checker.set_as_available("nix-prefetch-url") self.availability_checker.set_as_available("nix-prefetch-git") self.nix_build_hasher.sha256_sum = "nix build hash" self.nix_prefetch_hasher.sha256_sum = "nix prefetch hash" self.repository = GithubRepository(owner="test", name="test") self.revision = "test"
def setUp(self) -> None: self.url_hasher = FakeUrlHasher() self.revision_index_factory = FakeRevisionIndexFactory() self.expected_hash = "test hash" self.expected_revision = "test ref" self.url_hasher.sha256_sum = self.expected_hash self.revision_index_factory.revision_index = RevisionIndexImpl( ListRemote( symrefs={"HEAD": "refs/heads/master"}, heads={"master": self.expected_revision}, )) self.prefetcher = PrefetcherImpl( self.url_hasher, self.revision_index_factory, ) self.repository = GithubRepository("test owner", "test name")
def setUp(self) -> None: self.repository = GithubRepository(owner="test owner", name="test name") self.list_remote_factory = FakeListRemoteFactory() self.revision_index_factory = RevisionIndexFactoryImpl(self.list_remote_factory)
def test_for_non_existing_repo_we_get_none(self) -> None: repository = GithubRepository(owner="seppeljordan", name="repo_does_not_exist_12653") remote_list = self.factory.get_list_remote(repository) self.assertIsNone(remote_list)
def test_for_existing_repository_we_get_truthy_value(self) -> None: repository = GithubRepository(owner="seppeljordan", name="nix-prefetch-github") remote_list = self.factory.get_list_remote(repository) self.assertTrue(remote_list)