diff --git a/tests/test_modules/terraform/__init__.py b/tests/test_modules/terraform/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_modules/terraform/test_handle_apply_arguments_parsing.py b/tests/test_modules/terraform/test_handle_apply_arguments_parsing.py deleted file mode 100644 index 568cf33..0000000 --- a/tests/test_modules/terraform/test_handle_apply_arguments_parsing.py +++ /dev/null @@ -1,156 +0,0 @@ -import pytest -from typing import List -from leverage.modules.terraform import handle_apply_arguments_parsing - - -class TestHandleApplyArgumentsParsing: - @pytest.mark.parametrize( - "input_args, expected_output", - [ - # Test case: No arguments - ( - [], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - ], - ), - # Test case: -var="my_variable=test" - ( - ["-var=my_variable=test"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-var=my_variable=test", - ], - ), - # Test case: -var-file="varfile.tfvars" - ( - ["-var-file=varfile.tfvars"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-var-file=varfile.tfvars", - ], - ), - # Test case: -target="module.appgw.0" - ( - ["-target=module.appgw.0"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-target=module.appgw.0", - ], - ), - # Test case: -target "module.appgw.0" - ( - ["-target", "module.appgw.0"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-target", - "module.appgw.0", - ], - ), - # Test case: -lock=false - ( - ["-lock=false"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-lock=false", - ], - ), - # Test case: -parallelism=4 - ( - ["-parallelism=4"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-parallelism=4", - ], - ), - # Test case: -compact-warnings - ( - ["-compact-warnings"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-compact-warnings", - ], - ), - # Test case: -input=false - ( - ["-input=false"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-input=false", - ], - ), - # Test case: -json - ( - ["-json"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-json", - ], - ), - # Test case: -lock-timeout=60 - ( - ["-lock-timeout=60"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-lock-timeout=60", - ], - ), - # Test case: -json -auto-approve - ( - ["-json", "-auto-approve"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-json", - "-auto-approve", - ], - ), - # Test case: -no-color - ( - ["-no-color"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-no-color", - ], - ), - # Test case: -json -no-color my_plan - (["-json", "-no-color", "my_plan"], ["-json", "-no-color", "my_plan"]), - # Test case: -target=helm_release.cluster_autoscaling - ( - ["-target=helm_release.cluster_autoscaling"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-target=helm_release.cluster_autoscaling", - ], - ), - # Test case: -target helm_release.cluster_autoscaling - ( - ["-target", "helm_release.cluster_autoscaling"], - [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - "-target", - "helm_release.cluster_autoscaling", - ], - ), - ], - ) - def test_handle_apply_arguments_parsing(self, input_args: List[str], expected_output: List[str]): - default_args = [ - "-var-file=/project/apps-devstg/config/backend.tfvars", - "-var-file=/project/apps-devstg/config/account.tfvars", - ] - assert handle_apply_arguments_parsing(default_args, input_args) == expected_output diff --git a/tests/test_modules/test_terraform.py b/tests/test_modules/test_terraform.py index d8030bc..7d1fae7 100644 --- a/tests/test_modules/test_terraform.py +++ b/tests/test_modules/test_terraform.py @@ -7,6 +7,7 @@ from leverage._utils import AwsCredsContainer from leverage.container import TerraformContainer from leverage.modules.terraform import _init +from leverage.modules.terraform import there_is_a_plan_file from tests.test_containers import container_fixture_factory @@ -55,3 +56,32 @@ def test_init_with_args(terraform_container): mocked_pty.call_args_list[0].kwargs["command"] == f"terraform init -migrate-state -backend-config=/project/./config/backend.tfvars" ) + + +@pytest.mark.parametrize( + "args, expected_output", + [ + # No arguments, there's no plan file + ([], False), + # One argument that doesn't begin with '-', it is a plan file + (["plan_file"], True), + # A single flag/mode, no plan file + (["-no-color"], False), + # A single argument that has -key=value form, no plan file + (["-val='NAME=value'"], False), + # One key value argument, no plan file + (["-target", "aws_iam_role.example_role"], False), + # One flag before a plan file + (["-compact-warnings", "plan_file"], True), + # One -key=value argument before a plan file + (["-lock=false", "plan_file"], True), + # One key value argument before a plan file + (["-lock-timeout", "5s", "plan_file"], True), + # Some other options + (["-no-color", "-auto-approve"], False), + (["-destroy", "-target", "aws_iam_role.example.role"], False), + (["-target=aws_iam_role.example_role", "-destroy"], False), + ], +) +def test_apply_arguments_have_plan_file(args, expected_output): + assert there_is_a_plan_file(tuple(args)) == expected_output