def test_show_workspace_with_no_color(self, workspace_setup_teardown, caplog): workspace_name = "test" with workspace_setup_teardown(workspace_name) as tf, caplog.at_level( logging.INFO): ret, out, err = tf.show_workspace(no_color=IsFlagged) assert ret == 0 assert err == "" assert "Command: terraform workspace show -no-color" in caplog.messages
def test_set_workspace_with_args(self, workspace_setup_teardown, caplog): workspace_name = "test" with workspace_setup_teardown(workspace_name) as tf, caplog.at_level( logging.INFO): ret, out, err = tf.set_workspace(workspace_name, current_path, no_color=IsFlagged) assert ret == 0 assert err == "" assert ( f"Command: terraform workspace select -no-color test {current_path}" in caplog.messages)
def test_apply_with_var_file(self, caplog: LogCaptureFixture): with caplog.at_level(logging.INFO): tf = Terraform(working_dir=current_path) folder = "var_to_output" tf.init(folder) tf.apply( folder, var_file=os.path.join(current_path, "tfvar_files", "test.tfvars"), ) for log in caplog.messages: if log.startswith("Command: terraform apply"): assert log.count("-var-file=") == 1
def test_output(self, caplog: LogCaptureFixture, output_all: bool): expected_value = "test" required_output = "test_output" with caplog.at_level(logging.INFO): tf = Terraform(working_dir=current_path, variables={"test_var": expected_value}) tf.init("var_to_output") tf.apply("var_to_output") params = tuple() if output_all else (required_output, ) result = tf.output(*params) if output_all: assert result[required_output]["value"] == expected_value else: assert result == expected_value assert expected_value in caplog.messages[-1]
def test_create_workspace_with_args(self, workspace_setup_teardown, caplog): workspace_name = "test" state_file_path = os.path.join(current_path, "test_tfstate_file2", "terraform.tfstate") with workspace_setup_teardown(workspace_name, create=False) as tf, caplog.at_level( logging.INFO): ret, out, err = tf.create_workspace("test", current_path, no_color=IsFlagged) assert ret == 0 assert err == "" assert ( f"Command: terraform workspace new -no-color test {current_path}" in caplog.messages)
def test_delete_workspace_with_args(self, workspace_setup_teardown, caplog): workspace_name = "test" with workspace_setup_teardown(workspace_name, delete=False) as tf, caplog.at_level( logging.INFO): tf.set_workspace("default") ret, out, err = tf.delete_workspace( workspace_name, current_path, force=IsFlagged, ) assert ret == 0 assert err == "" assert ( f"Command: terraform workspace delete -force test {current_path}" in caplog.messages)
def test_cmd( self, method: Callable[..., str], expected_output: str, expected_ret_code: int, expected_exception: bool, expected_logs: str, caplog: LogCaptureFixture, folder: str, ): with caplog.at_level(logging.INFO): tf = Terraform(working_dir=current_path) tf.init(folder) try: ret, out, _ = method(tf) assert not expected_exception except TerraformCommandError as e: assert expected_exception ret = e.returncode out = e.out assert expected_output in out assert expected_ret_code == ret assert expected_logs in caplog.text