Skip to content

Commit 3a78793

Browse files
committed
Tests: Properly catch all invalid artifacts
1 parent 049ca11 commit 3a78793

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/gardenlinux/s3/s3_artifacts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ def upload_from_directory(
192192
"paths": [],
193193
}
194194

195+
# Catch any invalid artifacts
196+
bad_files = [
197+
f
198+
for f in artifacts_dir.iterdir()
199+
if not f.name.startswith(cname)
200+
and f.suffix not in [".release", ".requirements"]
201+
]
202+
if bad_files:
203+
raise RuntimeError(
204+
f"Artifact name '{bad_files[0].name}' does not start with cname '{cname}'"
205+
)
206+
195207
for artifact in artifacts_dir.iterdir():
196208
if not artifact.match(f"{cname}*"):
197209
continue

tests/s3/test_s3_artifacts.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,6 @@ def test_upload_from_directory_arch_none_raises(monkeypatch, s3_setup):
161161
release_path = env.tmp_path / f"{env.cname}.release"
162162
release_path.write_text(RELEASE_DATA)
163163

164-
# Monkeypatch CName to simulate missing architecture
165-
import gardenlinux.s3.s3_artifacts as s3art
166-
167-
class DummyCName:
168-
arch = None
169-
170-
def __init__(self, cname):
171-
pass
172-
173-
monkeypatch.setattr(s3art, "CName", DummyCName)
174-
175164
# Act / Assert
176165
artifacts = S3Artifacts(env.bucket_name)
177166
with pytest.raises(RuntimeError, match="Architecture could not be determined"):
@@ -260,6 +249,8 @@ def test_upload_from_directory_commit_mismatch_raises(s3_setup):
260249
bad_data = RELEASE_DATA.replace("abc123", "wrong")
261250
release_path.write_text(bad_data)
262251
artifacts = S3Artifacts(env.bucket_name)
252+
253+
# Act / Assert
263254
with pytest.raises(RuntimeError, match="Commit ID"):
264255
artifacts.upload_from_directory(env.cname, env.tmp_path)
265256

0 commit comments

Comments
 (0)