diff --git a/terraform_pytest/main.py b/terraform_pytest/main.py index 8fee1ca..0a85ab1 100644 --- a/terraform_pytest/main.py +++ b/terraform_pytest/main.py @@ -4,8 +4,17 @@ import click -from terraform_pytest.constants import TF_REPO_PATH, TF_TEST_BINARY_PATH, TERRATEST_PROJECT_FOLDER -from terraform_pytest.utils import build_test_binary, get_services, patch_repository, run_terratest_tests +from terraform_pytest.constants import ( + TF_REPO_PATH, + TF_TEST_BINARY_PATH, + TERRATEST_PROJECT_FOLDER, +) +from terraform_pytest.utils import ( + build_test_binary, + get_services, + patch_repository, + run_terratest_tests, +) logging.basicConfig(level=logging.INFO) @@ -63,6 +72,7 @@ def clean_command(): os.remove(os.path.join(TF_TEST_BINARY_PATH, file)) logging.info("Done") + @click.command(name="terratest-tests", help="Run Golang Terratest tests") def terratest_tests(): logging.info(f"Running terratest tests from {TERRATEST_PROJECT_FOLDER} directory") @@ -73,6 +83,7 @@ def terratest_tests(): except Exception as e: logging.error(f"Failed to execute terratest tests: {str(e)}") + if __name__ == "__main__": cli.add_command(build_command) cli.add_command(patch_command) diff --git a/terraform_pytest/utils.py b/terraform_pytest/utils.py index 10fb451..72d0086 100644 --- a/terraform_pytest/utils.py +++ b/terraform_pytest/utils.py @@ -39,7 +39,12 @@ def execute_command( try: process = subprocess.run( - cmd, env=env_vars, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True + cmd, + env=env_vars, + cwd=cwd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, ) return_code = process.returncode output = process.stdout + "\n" + process.stderr @@ -156,6 +161,7 @@ def patch_repository(): if stdout: logging.info(f"{patch_file} has been patched successfully.") + def run_terratest_tests(terratest_path: str) -> Tuple[int, str]: """ Run the Golang Terratest tests for the specified project.