Ejemplo n.º 1
0
 def test_gen_cmd(
     self,
     args_list: Optional[List[str]],
     command: CdkCommandTypeDef,
     env_ci: bool,
     expected: List[str],
     include_context: bool,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test gen_cmd."""
     mocker.patch.object(CloudDevelopmentKit, "cli_args", ["cli_args"])
     mocker.patch.object(CloudDevelopmentKit, "cli_args_context",
                         ["cli_args_context"])
     generate_node_command = mocker.patch(f"{MODULE}.generate_node_command",
                                          return_value=["success"])
     runway_context.env.ci = env_ci
     obj = CloudDevelopmentKit(runway_context, module_root=tmp_path)
     assert (obj.gen_cmd(command,
                         args_list,
                         include_context=include_context) ==
             generate_node_command.return_value)
     generate_node_command.assert_called_once_with(
         command="cdk",
         command_opts=expected,
         logger=obj.logger,
         package="aws-cdk",
         path=obj.path,
     )
Ejemplo n.º 2
0
 def test_cdk_deploy(
     self,
     caplog: LogCaptureFixture,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test cdk_deploy."""
     caplog.set_level(logging.INFO, logger=MODULE)
     mock_gen_cmd = mocker.patch.object(CloudDevelopmentKit,
                                        "gen_cmd",
                                        return_value=["deploy"])
     mock_run_module_command = mocker.patch(f"{MODULE}.run_module_command")
     obj = CloudDevelopmentKit(runway_context, module_root=tmp_path)
     assert not obj.cdk_deploy()
     mock_gen_cmd.assert_called_once_with("deploy", ['"*"'],
                                          include_context=True)
     mock_run_module_command.assert_called_once_with(
         cmd_list=mock_gen_cmd.return_value,
         env_vars=runway_context.env.vars,
         logger=obj.logger,
     )
     logs = "\n".join(caplog.messages)
     assert "deploy (in progress)" in logs
     assert "deploy (complete)" in logs
Ejemplo n.º 3
0
 def test_init(self, caplog: LogCaptureFixture,
               runway_context: RunwayContext, tmp_path: Path) -> None:
     """Test init."""
     caplog.set_level(logging.WARNING, logger=MODULE)
     obj = CloudDevelopmentKit(runway_context, module_root=tmp_path)
     assert not obj.init()
     assert (
         f"init not currently supported for {CloudDevelopmentKit.__name__}"
         in caplog.messages)
Ejemplo n.º 4
0
 def test_skip(
     self,
     caplog: LogCaptureFixture,
     expected: bool,
     explicitly_enabled: bool,
     mocker: MockerFixture,
     package_json_missing: bool,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test skip."""
     caplog.set_level(logging.INFO, logger=MODULE)
     mocker.patch.object(
         CloudDevelopmentKit,
         "package_json_missing",
         return_value=package_json_missing,
     )
     assert (CloudDevelopmentKit(
         runway_context,
         explicitly_enabled=explicitly_enabled,
         module_root=tmp_path,
     ).skip is expected)
     if package_json_missing:
         assert "skipped; package.json" in "\n".join(caplog.messages)
     elif not explicitly_enabled:
         assert "skipped; environment required but not defined" in "\n".join(
             caplog.messages)
Ejemplo n.º 5
0
    def test_run_build_steps_raise_file_not_found(
        self,
        caplog: LogCaptureFixture,
        fake_process: FakeProcess,
        platform_linux: None,
        runway_context: RunwayContext,
        tmp_path: Path,
    ) -> None:
        """Test run_build_steps."""
        caplog.set_level(logging.ERROR, MODULE)

        def _callback(process: FakePopen) -> None:
            process.returncode = 1
            raise FileNotFoundError

        fake_process.register_subprocess(["test", "step"], callback=_callback)
        with pytest.raises(FileNotFoundError):
            CloudDevelopmentKit(
                runway_context,
                module_root=tmp_path,
                options={
                    "build_steps": ["test step"]
                },
            ).run_build_steps()
        assert fake_process.call_count(["test", "step"]) == 1
        assert "failed to find it" in "\n".join(caplog.messages)
Ejemplo n.º 6
0
 def test_run_build_steps_empty(
     self,
     caplog: LogCaptureFixture,
     fake_process: FakeProcess,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test run_build_steps."""
     caplog.set_level(logging.INFO, logger=MODULE)
     obj = CloudDevelopmentKit(runway_context,
                               module_root=tmp_path,
                               options={"build_steps": []})
     assert not obj.run_build_steps()
     logs = "\n".join(caplog.messages)
     assert "build steps (in progress)" not in logs
     assert "build steps (complete)" not in logs
Ejemplo n.º 7
0
 def test_plan(
     self,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     skip: bool,
     tmp_path: Path,
 ) -> None:
     """Test plan."""
     mocker.patch.object(CloudDevelopmentKit, "skip", skip)
     cdk_bootstrap = mocker.patch.object(CloudDevelopmentKit,
                                         "cdk_bootstrap")
     cdk_list = mocker.patch.object(CloudDevelopmentKit,
                                    "cdk_list",
                                    return_value=["Stack0", "Stack1"])
     cdk_diff = mocker.patch.object(CloudDevelopmentKit, "cdk_diff")
     npm_install = mocker.patch.object(CloudDevelopmentKit, "npm_install")
     run_build_steps = mocker.patch.object(CloudDevelopmentKit,
                                           "run_build_steps")
     assert not CloudDevelopmentKit(runway_context,
                                    module_root=tmp_path).plan()
     cdk_bootstrap.assert_not_called()
     if skip:
         cdk_list.assert_not_called()
         cdk_diff.assert_not_called()
         npm_install.assert_not_called()
         run_build_steps.assert_not_called()
     else:
         cdk_list.assert_called_once_with()
         cdk_diff.assert_has_calls([call("Stack0"), call("Stack1")])
         npm_install.assert_called_once_with()
         run_build_steps.assert_called_once_with()
Ejemplo n.º 8
0
 def test_destroy(
     self,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     skip: bool,
     tmp_path: Path,
 ) -> None:
     """Test destroy."""
     mocker.patch.object(CloudDevelopmentKit, "skip", skip)
     cdk_bootstrap = mocker.patch.object(CloudDevelopmentKit,
                                         "cdk_bootstrap")
     cdk_destroy = mocker.patch.object(CloudDevelopmentKit, "cdk_destroy")
     npm_install = mocker.patch.object(CloudDevelopmentKit, "npm_install")
     run_build_steps = mocker.patch.object(CloudDevelopmentKit,
                                           "run_build_steps")
     assert not CloudDevelopmentKit(runway_context,
                                    module_root=tmp_path).destroy()
     cdk_bootstrap.assert_not_called()
     if skip:
         cdk_destroy.assert_not_called()
         npm_install.assert_not_called()
         run_build_steps.assert_not_called()
     else:
         cdk_destroy.assert_called_once_with()
         npm_install.assert_called_once_with()
         run_build_steps.assert_called_once_with()
Ejemplo n.º 9
0
 def test_cdk_list_empty(
     self,
     fake_process: FakeProcess,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test cdk_list empty."""
     mock_gen_cmd = mocker.patch.object(CloudDevelopmentKit,
                                        "gen_cmd",
                                        return_value=["list"])
     fake_process.register_subprocess(mock_gen_cmd.return_value,
                                      returncode=0,
                                      stdout="")
     obj = CloudDevelopmentKit(runway_context, module_root=tmp_path)
     assert obj.cdk_list() == [""]
     assert fake_process.call_count(mock_gen_cmd.return_value) == 1
Ejemplo n.º 10
0
 def test_cdk_list(
     self,
     fake_process: FakeProcess,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test cdk_list."""
     mock_gen_cmd = mocker.patch.object(CloudDevelopmentKit,
                                        "gen_cmd",
                                        return_value=["list"])
     fake_process.register_subprocess(mock_gen_cmd.return_value,
                                      returncode=0,
                                      stdout="Stack0\nStack1")
     obj = CloudDevelopmentKit(runway_context, module_root=tmp_path)
     assert obj.cdk_list() == ["Stack0", "Stack1"]
     mock_gen_cmd.assert_called_once_with("list", include_context=True)
     assert fake_process.call_count(mock_gen_cmd.return_value) == 1
Ejemplo n.º 11
0
 def test_cli_args_context(
     self,
     expected: List[str],
     runway_context: RunwayContext,
     parameters: Dict[str, Any],
     tmp_path: Path,
 ) -> None:
     """Test cli_args_context."""
     assert (CloudDevelopmentKit(
         runway_context, module_root=tmp_path,
         parameters=parameters).cli_args_context == expected)
Ejemplo n.º 12
0
 def test_cdk_deploy_raise_called_process_error(
     self,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test cdk_deploy raise CalledProcessError."""
     mocker.patch.object(CloudDevelopmentKit, "gen_cmd")
     mocker.patch(f"{MODULE}.run_module_command",
                  side_effect=CalledProcessError(1, ""))
     with pytest.raises(CalledProcessError):
         CloudDevelopmentKit(runway_context,
                             module_root=tmp_path).cdk_deploy()
Ejemplo n.º 13
0
 def test_cli_args(
     self,
     debug: bool,
     expected: List[str],
     no_color: bool,
     tmp_path: Path,
     verbose: bool,
 ) -> None:
     """Test cli_args."""
     assert (CloudDevelopmentKit(
         Mock(env=Mock(debug=debug, verbose=verbose), no_color=no_color),
         module_root=tmp_path,
     ).cli_args == expected)
Ejemplo n.º 14
0
 def test_run_build_steps_linux(
     self,
     caplog: LogCaptureFixture,
     fake_process: FakeProcess,
     mocker: MockerFixture,
     platform_linux: None,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test run_build_steps."""
     caplog.set_level(logging.INFO, logger=MODULE)
     fix_windows_command_list = mocker.patch(
         f"{MODULE}.fix_windows_command_list")
     fake_process.register_subprocess(["test", "step"], returncode=0)
     obj = CloudDevelopmentKit(runway_context,
                               module_root=tmp_path,
                               options={"build_steps": ["test step"]})
     assert not obj.run_build_steps()
     fix_windows_command_list.assert_not_called()
     assert fake_process.call_count(["test", "step"]) == 1
     logs = "\n".join(caplog.messages)
     assert "build steps (in progress)" in logs
     assert "build steps (complete)" in logs
Ejemplo n.º 15
0
 def test_run_build_steps_raise_called_process_error(
     self,
     fake_process: FakeProcess,
     platform_linux: None,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test run_build_steps."""
     fake_process.register_subprocess(["test", "step"], returncode=1)
     with pytest.raises(CalledProcessError):
         CloudDevelopmentKit(
             runway_context,
             module_root=tmp_path,
             options={
                 "build_steps": ["test step"]
             },
         ).run_build_steps()
     assert fake_process.call_count(["test", "step"]) == 1
Ejemplo n.º 16
0
 def test_cdk_list_raise_called_process_error(
     self,
     fake_process: FakeProcess,
     mocker: MockerFixture,
     runway_context: RunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test cdk_list raise CalledProcessError."""
     mock_gen_cmd = mocker.patch.object(CloudDevelopmentKit,
                                        "gen_cmd",
                                        return_value=["list"])
     fake_process.register_subprocess(
         mock_gen_cmd.return_value,
         returncode=1,
     )
     with pytest.raises(CalledProcessError):
         CloudDevelopmentKit(runway_context,
                             module_root=tmp_path).cdk_list()
     assert fake_process.call_count(mock_gen_cmd.return_value) == 1