Repository navigation
Expand file tree
/
Copy pathtest_tilt.py
More file actions
122 lines (99 loc) · 4.35 KB
/
Copy pathtest_tilt.py
File metadata and controls
122 lines (99 loc) · 4.35 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""ch_cli_tools.tilt generator tests. See test_model.py (this folder) for the
structural/model tests these build on, and ch_cli_tools/tilt.py's own
module docstring for the generation algorithm.
"""
from conftest import CLOUDHARNESS_ROOT, RESOURCES, chain
from test_util import write_tree_from_yaml
from ch_cli_tools import CHDeployConfig, CHProject
def _tilt_project(
tmp_path, *, subdomain="mysubdomain", service_auto=True, deployment_auto=False
):
write_tree_from_yaml(
tmp_path,
f"""
deployment-configuration:
values-template.yaml: |
name: testproj
mainapp: myapp
applications:
myapp:
Dockerfile: |
FROM scratch
tasks:
mytask:
Dockerfile: |
FROM scratch
deploy:
values.yaml: |
harness:
subdomain: {subdomain}
service:
auto: {str(service_auto).lower()}
deployment:
auto: {str(deployment_auto).lower()}
""",
)
return CHProject(tmp_path, config=CHDeployConfig())
def test_app_artifact_has_build_args_and_source_images(tmp_path):
project = _tilt_project(tmp_path)
images = {a["app_key"]: a for a in project.tilt._collect_artifacts().values()}
myapp = images["myapp"]
assert myapp["image"] == "testproj/myapp"
assert myapp["docker"]["dockerfile"].endswith("Dockerfile")
assert myapp["docker"]["buildArgs"] == {}
def test_task_artifact_is_marked_is_task(tmp_path):
project = _tilt_project(tmp_path)
images = {a["app_key"]: a for a in project.tilt._collect_artifacts().values()}
task = images["myapp-mytask"]
assert task["is_task"] is True
assert task["is_app"] is False
assert task["parent_app_name"] == "myapp"
def test_is_app_driven_by_service_auto_not_deployment_auto(tmp_path):
project = _tilt_project(tmp_path, service_auto=False, deployment_auto=True)
images = {a["app_key"]: a for a in project.tilt._collect_artifacts().values()}
assert images["myapp"]["is_app"] is False
project = _tilt_project(tmp_path, service_auto=True, deployment_auto=False)
images = {a["app_key"]: a for a in project.tilt._collect_artifacts().values()}
assert images["myapp"]["is_app"] is True
def test_rendered_tiltfile_groups_task_under_parent_app_key_even_when_subdomain_differs(
tmp_path,
):
# myapp's Tilt UI link uses its subdomain ("totallydifferent"), but the
# extra_env grouping below must still key off the stable app_key ("myapp") -
# legacy itself matched against the subdomain-swapped display name here,
# which silently breaks this grouping whenever subdomain != app name.
project = _tilt_project(tmp_path, subdomain="totallydifferent")
tiltfile = project.tilt.generate(write_on_disk=False)
assert 'extra_env.setdefault("myapp", [])' in tiltfile
assert 'extra_env["myapp"].append("testproj/myapp-mytask")' in tiltfile
assert "link('http://totallydifferent." in tiltfile
assert "k8s_resource(\n 'myapp'," in tiltfile
def test_task_build_sets_match_in_env_vars(tmp_path):
project = _tilt_project(tmp_path)
tiltfile = project.tilt.generate(write_on_disk=False)
assert "ref='testproj/myapp-mytask'" in tiltfile
assert (
"match_in_env_vars=True"
in tiltfile.split("ref='testproj/myapp-mytask'")[1].split("\n")[0]
)
assert (
"match_in_env_vars=True"
not in tiltfile.split("ref='testproj/myapp'")[1].split("\n")[0]
)
def test_base_images_are_always_included_even_without_a_deployed_dependent():
# cloudharness-base/my-common etc. must appear regardless of whether any
# currently-included app actually depends on them - matches legacy's own
# unconditional base/static-image scan.
project = chain(
CLOUDHARNESS_ROOT, RESOURCES, config=CHDeployConfig(includes=["events"])
)
artifacts = project.tilt._collect_artifacts()
assert "cloudharness-base" in artifacts
assert "my-common" in artifacts
def test_write_on_disk_writes_plain_text_tiltfile(tmp_path):
project = _tilt_project(tmp_path)
out = tmp_path / "out"
project.tilt.generate(output_path=str(out))
written = (out / "Tiltfile").read_text()
assert written.startswith("load(")
assert "docker_build(ref='testproj/myapp'" in written