-
Notifications
You must be signed in to change notification settings - Fork 1
[TESTS] Add tests for the s3 module
#150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b23a05a
Add moto dependency for s3 mocking
ByteOtter 44b2c48
Test: Add tests for Bucket class
ByteOtter a190283
Test: Add tests for S3Artifact class
ByteOtter 3d50907
Format code and fix bandit error for md5 use in mock
ByteOtter a4190b9
Tests: Rewrite S3Artifact tests
ByteOtter 1c490eb
Tests: Split fixtures and mocks into conftest
ByteOtter a3452fd
Tests: Refactor Bucket tests to use fixtures
ByteOtter 5a7dbae
Tests: Extract release data into constant
ByteOtter 445a4e4
Fix comment in test_bucket.py
ByteOtter 32caa13
Tests: Use original CName and use dataclass instead of tuple for fixture
ByteOtter f3f8c2f
Fix `DeprecationWarning: 'maxsplit'` for `re.split()`
NotTheEvilOne 6b57f2f
Code cleanup
NotTheEvilOne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import pytest | ||
| from pathlib import Path | ||
| from moto import mock_aws | ||
| from hashlib import md5, sha256 | ||
| import boto3 | ||
|
|
||
|
|
||
| # Dummy CName replacement | ||
| class DummyCName: | ||
| def __init__(self, cname): # pylint: disable=unused-argument | ||
| self.platform = "aws" | ||
| self.arch = "amd64" | ||
| self.version = "1234.1" | ||
| self.commit_id = "abc123" | ||
|
|
||
|
|
||
| # Helpers to compute digests for fake files | ||
| def dummy_digest(data: bytes, algo: str) -> str: | ||
| """ | ||
| Dummy for file_digest() to compute hashes for in-memory byte streams | ||
| """ | ||
| content = data.read() | ||
| data.seek(0) # Reset byte cursor to start for multiple uses | ||
|
|
||
| if algo == "md5": | ||
| return md5(content) # nosec B324 | ||
| elif algo == "sha256": | ||
| return sha256(content) | ||
| else: | ||
| raise ValueError(f"Unsupported algo: {algo}") | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def s3_setup(tmp_path, monkeypatch): | ||
| """ | ||
| Provides a clean S3 setup for each test. | ||
| """ | ||
| with mock_aws(): | ||
| s3 = boto3.resource("s3", region_name="us-east-1") | ||
| bucket_name = "test-bucket" | ||
| s3.create_bucket(Bucket=bucket_name) | ||
|
|
||
| monkeypatch.setattr("gardenlinux.s3.s3_artifacts.CName", DummyCName) | ||
| monkeypatch.setattr("gardenlinux.s3.s3_artifacts.file_digest", dummy_digest) | ||
|
|
||
| yield s3, bucket_name, tmp_path | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.