Repository navigation
Expand file tree
/
Copy pathtest_migration.py
More file actions
113 lines (91 loc) · 2.98 KB
/
Copy pathtest_migration.py
File metadata and controls
113 lines (91 loc) · 2.98 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
"""ch_cli_tools.migration tests. perform_migration is a standalone
search-and-replace tool, independent of CHProject - these exercise it
directly against a throwaway app tree, using the real, shipped migration
rule file (ch_cli_tools/migrations/1_migration.json).
"""
from test_util import write_tree_from_yaml
from ch_cli_tools.api import perform_migration
def test_perform_migration_replaces_deprecated_base_image_name_in_dockerfile(tmp_path):
write_tree_from_yaml(
tmp_path,
"""
applications:
myapp:
Dockerfile: |
FROM cloudharness-base-debian
""",
)
perform_migration(str(tmp_path), accept_all=True)
dockerfile = (tmp_path / "applications" / "myapp" / "Dockerfile").read_text()
assert dockerfile == "FROM cloudharness-base\n"
def test_perform_migration_replaces_pattern_scoped_keyword_in_yaml(tmp_path):
write_tree_from_yaml(
tmp_path,
"""
applications:
myapp:
deploy:
values.yaml: |
image: CLOUDHARNESS_BASE_DEBIAN
""",
)
perform_migration(str(tmp_path), accept_all=True)
values = (
tmp_path / "applications" / "myapp" / "deploy" / "values.yaml"
).read_text()
assert values == "image: CLOUDHARNESS_BASE\n"
def test_perform_migration_leaves_unrelated_content_untouched(tmp_path):
write_tree_from_yaml(
tmp_path,
"""
applications:
myapp:
Dockerfile: |
FROM scratch
""",
)
perform_migration(str(tmp_path), accept_all=True)
dockerfile = (tmp_path / "applications" / "myapp" / "Dockerfile").read_text()
assert dockerfile == "FROM scratch\n"
def test_perform_migration_accepts_a_list_of_base_roots(tmp_path):
first = write_tree_from_yaml(
tmp_path / "first",
"""
applications:
appone:
Dockerfile: |
FROM cloudharness-base-debian
""",
)
second = write_tree_from_yaml(
tmp_path / "second",
"""
applications:
apptwo:
Dockerfile: |
FROM cloudharness-base-debian
""",
)
perform_migration([str(first), str(second)], accept_all=True)
assert (
first / "applications" / "appone" / "Dockerfile"
).read_text() == "FROM cloudharness-base\n"
assert (
second / "applications" / "apptwo" / "Dockerfile"
).read_text() == "FROM cloudharness-base\n"
def test_perform_migration_without_accept_all_prompts_and_respects_the_answer(
tmp_path, monkeypatch
):
write_tree_from_yaml(
tmp_path,
"""
applications:
myapp:
Dockerfile: |
FROM cloudharness-base-debian
""",
)
monkeypatch.setattr("builtins.input", lambda: "n")
perform_migration(str(tmp_path), accept_all=False)
dockerfile = (tmp_path / "applications" / "myapp" / "Dockerfile").read_text()
assert dockerfile == "FROM cloudharness-base-debian\n"