示例#1
0
    def test_auto_tfvars(
        self,
        caplog: LogCaptureFixture,
        mocker: MockerFixture,
        runway_context: MockRunwayContext,
        tmp_path: Path,
    ) -> None:
        """Test auto_tfvars."""
        caplog.set_level(LogLevels.DEBUG, logger=MODULE)
        mock_tfenv = MagicMock(current_version="0.12.0")
        mocker.patch.object(Terraform, "tfenv", mock_tfenv)
        options = {
            "terraform_write_auto_tfvars": True,
        }
        parameters = {"key": "val"}
        obj = Terraform(runway_context,
                        module_root=tmp_path,
                        options=options,
                        parameters=parameters)
        assert obj.auto_tfvars.is_file()
        assert json.loads(obj.auto_tfvars.read_text()) == parameters
        assert "unable to parse current version" not in "\n".join(
            caplog.messages)

        # check cases where the file will not be written
        obj.auto_tfvars.unlink()
        del obj.auto_tfvars
        obj.options.write_auto_tfvars = False
        assert not obj.auto_tfvars.exists()  # type: ignore

        del obj.auto_tfvars
        obj.options.write_auto_tfvars = True
        obj.parameters = {}
        assert not obj.auto_tfvars.exists()  # type: ignore
示例#2
0
 def test_skip(
     self,
     env: bool,
     param: bool,
     expected: bool,
     mocker: MockerFixture,
     runway_context: MockRunwayContext,
     tmp_path: Path,
 ) -> None:
     """Test skip."""
     mocker.patch.object(Terraform, "env_file", env)
     obj = Terraform(runway_context, module_root=tmp_path)
     obj.parameters = param  # type: ignore
     assert obj.skip == expected