Skip to content

Commit

Permalink
Add tests for plan file detection
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofenoglio committed Aug 21, 2024
1 parent 89087bb commit 92d8bc3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 156 deletions.
Empty file.
156 changes: 0 additions & 156 deletions tests/test_modules/terraform/test_handle_apply_arguments_parsing.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/test_modules/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 92d8bc3

Please sign in to comment.