-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_build.py
More file actions
176 lines (162 loc) · 5.09 KB
/
test_build.py
File metadata and controls
176 lines (162 loc) · 5.09 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import re
from deploy.build import Build
from deploy.config import Config
from pathlib import Path
import pytest
@pytest.fixture
def base_config(tmp_path):
return {
"paths": {"store": Path()},
"builds": [],
"envs": [],
"areas": [],
"links": {},
}
def test_minimal_config(tmp_path, base_config):
config = Config.model_validate(base_config)
build = Build(Path("/dummy"), config, prefix=tmp_path)
assert build.packages == {}
@pytest.mark.parametrize(
"script_content,config_update,expected_hash",
[
pytest.param("content", {}, "e36260dc71ec23d2a4864cb91a6f4cf39a2382a8"),
pytest.param(
"different content", {}, "417c53f6642dacd630c04b68eafbf61cd71a5808"
),
pytest.param(
"content",
{"version": "1.0"},
"9071d31cc26091e45c4319fbf49523da9e9076e7",
),
pytest.param(
"different content",
{"version": "1.0"},
"7e460cb3aec91689ced8ede10f73b5572781b2c9",
),
pytest.param(
"content",
{"src": {"type": "git", "url": "https://example.com", "ref": "abcdefg"}},
"29babb628169cbc393ded61e18ee8d4e906a3a34",
id="git source",
),
pytest.param(
"content",
{"src": {"type": "file", "path": "build_A.sh"}},
"4881eaad3331c6285babfa160920db1d9cd19e35",
id="file source",
),
],
)
def test_single_package(
tmp_path, base_config, config_update, script_content, expected_hash
):
(tmp_path / "build_A.sh").write_text(script_content)
(tmp_path / "build_A.sh").chmod(0o755)
base_config["builds"].append(
{
"name": "A",
"version": "0.0",
"depends": [],
**config_update,
}
)
config = Config.model_validate(base_config)
build = Build(tmp_path, config, extra_scripts=tmp_path, prefix=tmp_path)
assert len(build.packages) == 1
assert "A" in build.packages
assert build.packages["A"].buildhash == expected_hash
@pytest.mark.parametrize(
"script_content_A,expected_hash_A,script_content_B,expected_hash_B",
[
pytest.param(
"content",
"e36260dc71ec23d2a4864cb91a6f4cf39a2382a8",
"content",
"1a077b36665b28a8141efe3cae6c8a0f56a00b59",
id="Base test",
),
pytest.param(
"changed content",
"b1193c02fb7e0a94012f5b6887f8186069dcb50c",
"content",
"c4b6e82573051e913a9f3d96577c62ec8d02a287",
id="Changes in A changes both hashes",
),
pytest.param(
"content",
"e36260dc71ec23d2a4864cb91a6f4cf39a2382a8",
"changed content",
"80a25fcb95675671b025346aa92950518f461120",
id="Changes in B only changes B's hash",
),
],
)
def test_package_dependency(
tmp_path,
base_config,
script_content_A,
expected_hash_A,
script_content_B,
expected_hash_B,
):
(tmp_path / "build_A.sh").write_text(script_content_A)
(tmp_path / "build_A.sh").chmod(0o755)
(tmp_path / "build_B.sh").write_text(script_content_B)
(tmp_path / "build_B.sh").chmod(0o755)
base_config["builds"] = [
{
"name": "A",
"version": "0.0",
"depends": [],
},
{
"name": "B",
"version": "0.0",
"depends": ["A"],
},
]
config = Config.model_validate(base_config)
build = Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)
assert len(build.packages) == 2
assert build.packages["A"].buildhash == expected_hash_A
assert build.packages["B"].buildhash == expected_hash_B
def test_build_script_validity(
tmp_path,
base_config,
):
base_config["builds"] = [
{
"name": "A",
"version": "0.0",
"depends": [],
},
{
"name": "B",
"version": "0.0",
"depends": ["A"],
},
]
config = Config.model_validate(base_config)
# Test that if no files are present, the first package will error
with pytest.raises(
SystemExit,
match=re.escape(
"Build script for package A (build_A.sh) wasn't found or it isn't executable"
),
):
_ = Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)
# Test that if both files exist, but only the first one is executable, we'll
# error on the second
(tmp_path / "build_A.sh").write_text("")
(tmp_path / "build_A.sh").chmod(0o755)
(tmp_path / "build_B.sh").write_text("")
with pytest.raises(
SystemExit,
match=re.escape(
"Build script for package B (build_B.sh) wasn't found or it isn't executable"
),
):
_ = Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)
# Check that the correct configuration is correct
(tmp_path / "build_B.sh").chmod(0o755)
Build(Path("/dummy"), config, extra_scripts=tmp_path, prefix=tmp_path)