Repository navigation
Expand file tree
/
Copy pathtest_dependency_graph.py
More file actions
53 lines (45 loc) · 2.26 KB
/
Copy pathtest_dependency_graph.py
File metadata and controls
53 lines (45 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Inspect the real OpenTofu dependency graph, without credentials or apply."""
from collections import defaultdict
from pathlib import Path
import re
import shutil
import subprocess
import unittest
@unittest.skipUnless(shutil.which("tofu"), "OpenTofu must be on PATH for graph tests")
class DependencyTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
graph = subprocess.run(["tofu", "graph"], cwd=Path(__file__).parent,
check=True, capture_output=True, text=True).stdout
cls.edges = defaultdict(set)
for source, target in re.findall(r'"\[root\] ([^"\\]+)" -> "\[root\] ([^"\\]+)"', graph):
cls.edges[source.split(" (")[0]].add(target.split(" (")[0])
def dependencies(self, resource):
visited = set()
pending = [resource]
while pending:
node = pending.pop()
if node not in visited:
visited.add(node)
pending.extend(self.edges[node])
return visited
def test_artifact_updates_cannot_change_subscription_inputs(self):
for resource in ["aws_cloudformation_stack.pro", "aws_cloudfront_distribution.cdn",
"aws_s3_bucket.artifacts"]:
with self.subTest(resource=resource):
self.assertIn(resource, self.edges)
self.assertNotIn("var.artifact_manifest", self.dependencies(resource))
self.assertNotIn("terraform_data.activate_pro", self.dependencies(resource))
def test_publication_waits_for_activation(self):
for resource in ["aws_route53_record.ipv4", "aws_route53_record.ipv6",
"aws_s3_bucket_policy.artifacts", "aws_s3_object.payload",
"aws_s3_object.installer_data", "aws_s3_object.latest",
"aws_s3_object.bootstrap"]:
with self.subTest(resource=resource):
self.assertIn("terraform_data.activate_pro", self.dependencies(resource))
def test_manifest_change_rechecks_existing_subscription(self):
deps = self.dependencies("terraform_data.activate_pro")
self.assertIn("var.artifact_manifest", deps)
self.assertIn("aws_cloudformation_stack.pro", deps)
if __name__ == "__main__":
unittest.main()