• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 18847018991

27 Oct 2025 03:45PM UTC coverage: 92.254% (+12.0%) from 80.282%
18847018991

Pull #22816

github

web-flow
Merge f1312fa87 into 06e216752
Pull Request #22816: Update Pants internal Python to 3.14

39 of 40 new or added lines in 11 files covered. (97.5%)

382 existing lines in 22 files now uncovered.

89230 of 96722 relevant lines covered (92.25%)

3.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.93
/src/python/pants/backend/terraform/goals/deploy_test.py
1
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
1✔
4

5
import json
1✔
6
import shlex
1✔
7

8
import pytest
1✔
9

10
from pants.backend.terraform.goals.deploy import DeployTerraformFieldSet
1✔
11
from pants.backend.terraform.testutil import rule_runner_with_auto_approve, standard_deployment
1✔
12
from pants.core.goals.deploy import Deploy, DeployProcess
1✔
13
from pants.engine.internals.native_engine import Address
1✔
14
from pants.testutil.rule_runner import RuleRunner, mock_console
1✔
15

16
rule_runner = rule_runner_with_auto_approve
1✔
17
standard_deployment = standard_deployment
1✔
18

19

20
def _extract_terraform_argv_from_script(script_argv) -> tuple[str, ...]:
1✔
21
    """Extract the argv of the invocation of Terraform from its launcher script."""
UNCOV
22
    script = script_argv[2]
×
UNCOV
23
    tf_invocation = script.split("&&")
×
UNCOV
24
    argv = shlex.split(tf_invocation[-1])
×
UNCOV
25
    return tuple(argv)
×
26

27

28
def test_run_terraform_deploy(rule_runner: RuleRunner, standard_deployment, tmpdir) -> None:
1✔
29
    """Test end-to-end running of a deployment."""
30
    rule_runner.write_files(standard_deployment.files)
1✔
31
    with mock_console(rule_runner.options_bootstrapper, stdin_content="yes") as (_, m):
1✔
32
        result = rule_runner.run_goal_rule(
1✔
33
            Deploy, args=["src/tf:stg", *rule_runner.options_bootstrapper.args]
34
        )
35

36
    # assert Pants thinks we succeeded
UNCOV
37
    assert result.stdout.splitlines() == []
×
UNCOV
38
    assert "✓ src/tf:stg deployed" in result.stderr.splitlines()
×
39

40
    # assert Terraform did things
UNCOV
41
    with open(standard_deployment.state_file) as raw_state_file:
×
UNCOV
42
        raw_state = raw_state_file.read()
×
UNCOV
43
    assert raw_state, "Terraform state file not found where expected."
×
UNCOV
44
    state = json.loads(raw_state)
×
UNCOV
45
    assert len(state["resources"]) == 1, "Resource not found in terraform state"
×
46

47

48
def test_deploy_terraform_forwards_args(rule_runner: RuleRunner, standard_deployment) -> None:
1✔
49
    rule_runner.write_files(standard_deployment.files)
1✔
50

51
    target = rule_runner.get_target(Address("src/tf", target_name="stg"))
1✔
52
    field_set = DeployTerraformFieldSet.create(target)
1✔
53
    deploy_process = rule_runner.request(DeployProcess, [field_set])
1✔
UNCOV
54
    assert deploy_process.process
×
55

UNCOV
56
    argv = _extract_terraform_argv_from_script(deploy_process.process.process.argv)
×
57

UNCOV
58
    assert "-chdir=src/tf" in argv, "Did not find expected -chdir"
×
UNCOV
59
    assert "-var-file=stg.tfvars" in argv, "Did not find expected -var-file"
×
UNCOV
60
    assert "-auto-approve" in argv, "Did not find expected passthrough args"
×
61

62

63
@pytest.mark.parametrize(
1✔
64
    "options,action,not_action",
65
    [
66
        ([], "apply", "plan"),
67
        (["--experimental-deploy-dry-run=False"], "apply", "plan"),
68
        (["--experimental-deploy-dry-run"], "plan", "apply"),
69
    ],
70
)
71
def test_deploy_terraform_adheres_to_dry_run_flag(
1✔
72
    rule_runner: RuleRunner, standard_deployment, options: list[str], action: str, not_action: str
73
) -> None:
74
    rule_runner.write_files(standard_deployment.files)
1✔
75
    rule_runner.set_options(options)
1✔
76

77
    target = rule_runner.get_target(Address("src/tf", target_name="stg"))
1✔
78
    field_set = DeployTerraformFieldSet.create(target)
1✔
79
    deploy_process = rule_runner.request(DeployProcess, [field_set])
1✔
UNCOV
80
    assert deploy_process.process
×
81

UNCOV
82
    argv = _extract_terraform_argv_from_script(deploy_process.process.process.argv)
×
83

UNCOV
84
    assert action in argv, f"Expected {action} in argv"
×
UNCOV
85
    assert not_action not in argv, f"Did not expect {not_action} in argv"
×
86

87

88
def test_deploy_terraform_with_module(rule_runner: RuleRunner) -> None:
1✔
89
    """Test that we can deploy a root module with a nearby shared module."""
90
    files = {
1✔
91
        "src/tf/root/BUILD": """terraform_deployment(root_module=":mod")\nterraform_module(name="mod")""",
92
        "src/tf/root/main.tf": """module "mod0" { source = "../mod0" }""",
93
        "src/tf/mod0/BUILD": """terraform_module()""",
94
        "src/tf/mod0/main.tf": """resource "null_resource" "dep" {}""",
95
    }
96
    rule_runner.write_files(files)
1✔
97

98
    with mock_console(rule_runner.options_bootstrapper, stdin_content="yes") as (_, m):
1✔
99
        result = rule_runner.run_goal_rule(
1✔
100
            Deploy, args=["src/tf::", *rule_runner.options_bootstrapper.args]
101
        )
102

103
    # assert Pants thinks we succeeded
UNCOV
104
    assert result.stdout.splitlines() == []
×
105

106
    # assert deployment succeeded
UNCOV
107
    assert "✓ src/tf/root:root deployed" in result.stderr.splitlines()
×
108
    # assert module was not deployed
UNCOV
109
    assert not any("src/tf/mod0" in line for line in result.stderr.splitlines())
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc