Skip to content

Commit 5550bba

Browse files
committed
Tests: Update tests to cover all changes
1 parent c78ed19 commit 5550bba

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

tests/s3/test_bucket.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
"""
99

1010
import io
11-
from pathlib import Path
12-
13-
import pytest
1411

1512
from gardenlinux.s3.bucket import Bucket
1613

1714
REGION = "us-east-1"
1815

1916

17+
def test_bucket_minimal(s3_setup):
18+
"""
19+
Ensure Bucket initializes correctly.
20+
"""
21+
env = s3_setup
22+
bucket = Bucket(env.bucket_name)
23+
assert bucket.name == env.bucket_name
24+
25+
2026
def test_objects_empty(s3_setup):
2127
"""
2228
List objects from empty bucket.

tests/s3/test_s3_artifacts.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,56 @@ def test_upload_from_directory_version_mismatch_raises(s3_setup):
202202
artifacts.upload_from_directory(env.cname, env.tmp_path)
203203

204204

205+
def test_upload_from_directory_none_version_raises(monkeypatch, s3_setup):
206+
"""
207+
Raise RuntimeError if CName.version is None.
208+
"""
209+
# Arrange
210+
env = s3_setup
211+
(env.tmp_path / f"{env.cname}.release").write_text(RELEASE_DATA)
212+
213+
import gardenlinux.s3.s3_artifacts as s3art
214+
215+
class DummyCName:
216+
arch = "amd64"
217+
version = None
218+
commit_id = "abc123"
219+
platform = "aws"
220+
221+
def __init__(self, cname):
222+
pass
223+
224+
monkeypatch.setattr(s3art, "CName", DummyCName)
225+
226+
artifacts = s3art.S3Artifacts(env.bucket_name)
227+
228+
# Act / Assert
229+
with pytest.raises(
230+
RuntimeError,
231+
match="Release file data and given cname conflict detected: Version None",
232+
):
233+
artifacts.upload_from_directory(env.cname, env.tmp_path)
234+
235+
236+
def test_upload_from_directory_invalid_artifact_name(s3_setup):
237+
"""
238+
Raise RuntimeError if artifact file does not start with cname.
239+
"""
240+
# Arrange
241+
env = s3_setup
242+
(env.tmp_path / f"{env.cname}.release").write_text(RELEASE_DATA)
243+
244+
# Create "bad" artifact that does not start with cname
245+
bad_file = env.tmp_path / "no_match"
246+
bad_file.write_bytes(b"oops")
247+
248+
artifacts = S3Artifacts(env.bucket_name)
249+
250+
# Act / Assert
251+
with pytest.raises(RuntimeError, match="does not start with cname"):
252+
artifacts.upload_from_directory(env.cname, env.tmp_path)
253+
254+
205255
def test_upload_from_directory_commit_mismatch_raises(s3_setup):
206256
"""Raise RuntimeError when commit ID is not matching with cname."""
207257
# Arrange

0 commit comments

Comments
 (0)