-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_my_module.py
More file actions
53 lines (39 loc) · 1.48 KB
/
test_my_module.py
File metadata and controls
53 lines (39 loc) · 1.48 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
import tftest
import pytest
tfvars = ["../my_tfvars/important.tfvars", "../my_tfvars/temp.tfvars"]
@pytest.fixture(params=tfvars)
def plan(request, direcory=".", module_name="my_tf_module"):
tfvars_file = request.param
tf = tftest.TerraformTest(module_name, direcory)
tf.setup()
plan = tf.plan(
output=True, use_cache=True, tf_var_file=tfvars_file
) # add tf_var_file
return plan
def test_variables(plan):
tf_vars = plan.variables
assert "prefix_name" in tf_vars
assert "file_content" in tf_vars
assert "Important" == tf_vars["prefix_name"]
def test_outputs(plan):
assert "file_names" in plan.outputs
first_file_path = f"./{plan.variables['prefix_name']}-file1.txt"
assert first_file_path == sorted(plan.outputs["file_names"])[0]
@pytest.fixture(params=tfvars)
def apply_output(request, direcory=".", module_name="my_tf_module"):
tfvars_file = request.param
tf = tftest.TerraformTest(module_name, direcory)
tf.setup()
tf.apply(output=True, use_cache=True, tf_var_file=tfvars_file)
output = tf.output()
yield output
tf.destroy(auto_approve=True, use_cache=True, tf_var_file=tfvars_file)
def test_apply(apply_output):
files = apply_output["file_names"]
assert len(files) == 3
def test_file_content(apply_output):
files = apply_output["file_names"]
for file in files:
file = file.replace("./", "./my_tf_module/")
content = open(file, "r")
assert "file content" in content.read()