-
-
Notifications
You must be signed in to change notification settings - Fork 744
Add share-log subcommand to upload install.log to paste.rs #4511
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
Open
Softer
wants to merge
9
commits into
archlinux:master
Choose a base branch
from
Softer:feat-share-log
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
727df5c
Add --share-log flag to upload install.log to paste.rs
Softer 995ee8a
Apply ruff-format to share_log.py
Softer cd6565d
Rework share-log per review: subcommand, TUI confirmation, truncate l…
Softer 38b8d11
Replace curl/SysCommand with urllib.request, remove defensive try/except
Softer dfccd1a
Merge remote-tracking branch 'origin/master' into feat-share-log
Softer c0f0234
Fix TUI imports after ui module was pulled one level up (#4515)
Softer 6f84eca
Decouple share_install_log from TUI module
Softer e8e24b9
Add unit tests for share_install_log function
Softer d7c8099
Update docs to use share-log subcommand syntax
Softer 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
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
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
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
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
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
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
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,94 @@ | ||
| # pylint: disable=redefined-outer-name | ||
| import urllib.error | ||
| from io import BytesIO | ||
| from pathlib import Path | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from archinstall.lib.output import share_install_log | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def log_file(tmp_path: Path) -> Path: | ||
| log_dir = tmp_path / 'archinstall' | ||
| log_dir.mkdir() | ||
| return log_dir / 'install.log' | ||
|
|
||
|
|
||
| def _fake_logger(log_file: Path) -> MagicMock: | ||
| mock = MagicMock() | ||
| mock.path = log_file | ||
| return mock | ||
|
|
||
|
|
||
| def test_file_not_found(tmp_path: Path) -> None: | ||
| missing = tmp_path / 'no-such' / 'install.log' | ||
| with patch('archinstall.lib.output.logger', _fake_logger(missing)): | ||
| assert share_install_log() == 1 | ||
|
|
||
|
|
||
| def test_empty_file(log_file: Path) -> None: | ||
| log_file.write_bytes(b'') | ||
| with patch('archinstall.lib.output.logger', _fake_logger(log_file)): | ||
| assert share_install_log() == 1 | ||
|
|
||
|
|
||
| def test_user_cancels(log_file: Path) -> None: | ||
| log_file.write_text('some log content') | ||
| with patch('archinstall.lib.output.logger', _fake_logger(log_file)): | ||
| assert share_install_log(confirm=lambda _: False) == 1 | ||
|
|
||
|
|
||
| def test_successful_upload(log_file: Path) -> None: | ||
| log_file.write_text('some log content') | ||
| fake_response = BytesIO(b'https://paste.rs/abc.def') | ||
|
|
||
| with ( | ||
| patch('archinstall.lib.output.logger', _fake_logger(log_file)), | ||
| patch('urllib.request.urlopen', return_value=fake_response) as mock_open, | ||
| ): | ||
| result = share_install_log() | ||
|
|
||
| assert result == 0 | ||
| req = mock_open.call_args[0][0] | ||
| assert req.data == b'some log content' | ||
|
|
||
|
|
||
| def test_truncation(log_file: Path) -> None: | ||
| max_size = 100 | ||
| content = b'A' * 50 + b'B' * 80 | ||
| log_file.write_bytes(content) | ||
| fake_response = BytesIO(b'https://paste.rs/abc.def') | ||
|
|
||
| with ( | ||
| patch('archinstall.lib.output.logger', _fake_logger(log_file)), | ||
| patch('urllib.request.urlopen', return_value=fake_response) as mock_open, | ||
| ): | ||
| result = share_install_log(max_size=max_size) | ||
|
|
||
| assert result == 0 | ||
| req = mock_open.call_args[0][0] | ||
| assert len(req.data) == max_size | ||
| assert req.data == content[-max_size:] | ||
|
|
||
|
|
||
| def test_network_error(log_file: Path) -> None: | ||
| log_file.write_text('some log content') | ||
|
|
||
| with ( | ||
| patch('archinstall.lib.output.logger', _fake_logger(log_file)), | ||
| patch('urllib.request.urlopen', side_effect=urllib.error.URLError('no network')), | ||
| ): | ||
| assert share_install_log() == 1 | ||
|
|
||
|
|
||
| def test_unexpected_response(log_file: Path) -> None: | ||
| log_file.write_text('some log content') | ||
| fake_response = BytesIO(b'ERROR: something went wrong') | ||
|
|
||
| with ( | ||
| patch('archinstall.lib.output.logger', _fake_logger(log_file)), | ||
| patch('urllib.request.urlopen', return_value=fake_response), | ||
| ): | ||
| assert share_install_log() == 1 | ||
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.