Exemplo n.º 1
0
def test_load_terraform_registry(
    git_getter,
    source,
    source_version,
    expected_content_path,
    expected_git_url,
    expected_dest_dir,
    expected_module_source,
    expected_inner_module,
):
    # given
    current_dir = Path(__file__).parent / "tmp"
    registry = ModuleLoaderRegistry(download_external_modules=True)

    # when
    content = registry.load(current_dir=str(current_dir),
                            source=source,
                            source_version=source_version)

    # then
    assert content.loaded()
    assert content.path() == str(
        Path(DEFAULT_EXTERNAL_MODULES_DIR) / expected_content_path)

    git_getter.assert_called_once_with(expected_git_url, mock.ANY)

    git_loader = next(loader for loader in registry.loaders
                      if isinstance(loader, GenericGitLoader))
    assert git_loader.dest_dir == str(
        Path(DEFAULT_EXTERNAL_MODULES_DIR) / expected_dest_dir)
    assert git_loader.module_source == expected_module_source
    assert git_loader.inner_module == expected_inner_module
Exemplo n.º 2
0
 def test_load_terraform_registry(self):
     registry = ModuleLoaderRegistry(True, DEFAULT_EXTERNAL_MODULES_DIR)
     source = "terraform-aws-modules/security-group/aws"
     with registry.load(current_dir=self.current_dir, source=source, source_version="~> 3.0") as content:
         assert content.loaded()
         expected_content_path = os.path.join(self.current_dir, DEFAULT_EXTERNAL_MODULES_DIR, source)
         self.assertEqual(expected_content_path, content.path(), f"expected content.path() to be {content.path()}, got {expected_content_path}")
Exemplo n.º 3
0
 def test_load_local_module_absolute_path(self):
     registry = ModuleLoaderRegistry(download_external_modules=True)
     source = "/some/module"
     try:
         registry.load(current_dir=self.current_dir, source=source, source_version="latest")
         self.assertEqual(1, 2, 'Module loading should have thrown an error')
     except FileNotFoundError as e:
         self.assertEqual(str(e), source)
Exemplo n.º 4
0
 def test_load_terraform_registry_check_cache(self):
     registry = ModuleLoaderRegistry(download_external_modules=True)
     source1 = "https://github.com/bridgecrewio/checkov_not_working1.git"
     registry.load(current_dir=self.current_dir, source=source1, source_version="latest")
     self.assertTrue(source1 in registry.failed_urls_cache)
     source2 = "https://github.com/bridgecrewio/checkov_not_working2.git"
     registry.load(current_dir=self.current_dir, source=source2, source_version="latest")
     self.assertTrue(source1 in registry.failed_urls_cache and source2 in registry.failed_urls_cache)
Exemplo n.º 5
0
 def test_load_terraform_registry(self):
     registry = ModuleLoaderRegistry(True, DEFAULT_EXTERNAL_MODULES_DIR)
     registry.root_dir = self.current_dir
     source = "terraform-aws-modules/security-group/aws"
     content = registry.load(current_dir=self.current_dir, source=source, source_version="~> 3.0")
     assert content.loaded()
     expected_content_path = os.path.join(
         self.current_dir,
         DEFAULT_EXTERNAL_MODULES_DIR,
         "github.com/terraform-aws-modules/terraform-aws-security-group",
     )
     self.assertRegex(content.path(), f"^{expected_content_path}/v3.*")
Exemplo n.º 6
0
def test_load_local_path(git_getter, source, expected_content_path, expected_exception):
    # given
    current_dir = Path(__file__).parent
    registry = ModuleLoaderRegistry()

    # when
    with expected_exception:
        content = registry.load(current_dir=str(current_dir), source=source, source_version="latest")

        # then
        assert content.loaded()
        assert content.path() == str(current_dir / expected_content_path)

        git_getter.assert_not_called()