Skip to content
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

Tests adjustment #299

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Environemt variables
| SUBPROCESS_TIMEOUT_SECS | int | Indicates how long subprocesses can last. Note that all backups are run from shell in subprocesses. Defaults to 3600 seconds which should be enough for even big dbs to make backup of. Min `5` and max `86400` (24h). | 3600 |
| ZIP_ARCHIVE_LEVEL | int | Compression level of 7-zip via `-mx` option: `-mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)`. Defaults to `3` which should be sufficient and fast enough. Min `1` and max `9`. | 3 |
| LOG_FOLDER_PATH | string | Path to store log files, for local development `./logs`, in container `/var/log/ogion`. | /var/log/ogion |
| SIGTERM_TIMEOUT_SECS | int | Time in seconds on exit how long ogion will wait for ongoing backup threads before force killing them and exiting. Min `0` and max `86400` (24h). | 30 |
| SIGTERM_TIMEOUT_SECS | int | Time in seconds on exit how long ogion will wait for ongoing backup threads before force killing them and exiting. Min `0` and max `86400` (24h). | 3600 |
| ZIP_SKIP_INTEGRITY_CHECK | bool | By default set to `false` and after 7zip archive is created, integrity check runs on it. You can opt out this behaviour for performance reasons, use `true`. | false |
| OGION_CPU_ARCHITECTURE | string | CPU architecture, supported `amd64` and `arm64`. Docker container will set it automatically so probably do not change it. | amd64 |

Expand Down
2 changes: 1 addition & 1 deletion ogion/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Settings(BaseSettings):
default="amd64", alias_priority=2, alias="OGION_CPU_ARCHITECTURE"
)
SUBPROCESS_TIMEOUT_SECS: float = Field(ge=5, le=3600 * 24, default=3600)
SIGTERM_TIMEOUT_SECS: float = Field(ge=0, le=3600 * 24, default=30)
SIGTERM_TIMEOUT_SECS: float = Field(ge=0, le=3600 * 24, default=3600)
ZIP_ARCHIVE_LEVEL: int = Field(ge=1, le=9, default=3)
BACKUP_MAX_NUMBER: int = Field(ge=1, le=998, default=7)
BACKUP_MIN_RETENTION_DAYS: int = Field(ge=0, le=36600, default=3)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,36 @@ def test_quit(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(main, "exit_event", exit_mock)
main.quit(1, None)
exit_mock.set.assert_called_once()


@pytest.mark.parametrize(
"cli_args,expected_attributes",
[
(["main.py", "--single"], {"single": True}),
(["main.py", "--debug-notifications"], {"debug_notifications": True}),
(
["main.py", "--debug-download", "example.log"],
{"debug_download": "example.log"},
),
(["main.py", "--list"], {"list": True}),
(["main.py", "--restore-latest"], {"restore_latest": True}),
(["main.py", "--target", "example_target"], {"target": "example_target"}),
(
["main.py", "--restore", "example_restore"],
{"restore": "example_restore"},
),
],
)
def test_setup_runtime_arguments_parametrized(
monkeypatch: pytest.MonkeyPatch,
cli_args: list[str],
expected_attributes: dict[str, bool | str],
) -> None:
monkeypatch.setattr("sys.argv", cli_args)

args: main.RuntimeArgs = main.setup_runtime_arguments()

assert isinstance(args, main.RuntimeArgs)

for attribute, expected_value in expected_attributes.items():
assert getattr(args, attribute) == expected_value