-
Notifications
You must be signed in to change notification settings - Fork 0
Add sync tests #64
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
Add sync tests #64
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2f82538
Add test_sync.py to test double-deprecation and removal issues
MJGaughran 203af40
Add test for external tool calls
MJGaughran fb92d97
Fix type hinting in test_sync and test_external_tools
MJGaughran 83efbcf
Have dedicated test for ensuring apptainer pulls are successful
MJGaughran 8b757c3
Add test for BinaryApp using a local generated file
MJGaughran c7bf870
Add test for syncing with nonexistent .git folder
MJGaughran 55190b2
Add tests for Module options not previously covered
MJGaughran 8a8a5dd
Reorganise test configuration for consistency
MJGaughran 6604ea4
Expand test_module_options to cover template branches
MJGaughran fc81679
Add test for deploying from scratch into dir with snapshot
MJGaughran 0ba2aa3
Add unit test for defensive check in apply_default_versions()
MJGaughran 52a667b
Add explicit default configuration to test_sync.py
MJGaughran 8cbd6d0
Use more specific pytest.raises matches in sync-related tests
MJGaughran 0dbb91f
Reword test config descriptions to clarify use
MJGaughran 119e3be
Update docstrings and comments for newer dependency pinning behaviour
MJGaughran a00da36
Fix test_dependencies_render_module_load_lines comments for accuracy
MJGaughran 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
19 changes: 19 additions & 0 deletions
19
tests/configs/valid/apptainer-pull/example-apptainer/1.0.yaml
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,19 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-apptainer | ||
| version: "1.0" | ||
| description: Minimal single-image module exercising a real apptainer pull | ||
|
|
||
| applications: | ||
| - app_type: apptainer | ||
|
|
||
| container: | ||
| path: docker://ghcr.io/apptainer/lolcow | ||
| version: latest | ||
|
|
||
| entrypoints: | ||
| - name: cowsay-hello | ||
| command: cowsay | ||
| options: | ||
| command_args: Hello |
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,3 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: {} |
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,3 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: {} |
8 changes: 8 additions & 0 deletions
8
tests/configs/valid/multi-version-active/example-module-multi/1.0.yaml
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,8 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "1.0" | ||
| description: Module with two versions | ||
|
|
||
| applications: [] |
8 changes: 8 additions & 0 deletions
8
tests/configs/valid/multi-version-active/example-module-multi/2.0.yaml
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,8 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "2.0" | ||
| description: Module with two versions | ||
|
|
||
| applications: [] |
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,3 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: {} |
12 changes: 12 additions & 0 deletions
12
tests/configs/valid/multi-version-deprecated/example-module-multi/1.0.yaml
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,12 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "1.0" | ||
| description: Module with two versions | ||
|
|
||
| applications: [] | ||
|
|
||
| # Deprecating both versions together moves their modulefile links into the deprecated | ||
| # area and clears the now-spent live modulefiles name folder. | ||
| deprecated: true |
12 changes: 12 additions & 0 deletions
12
tests/configs/valid/multi-version-deprecated/example-module-multi/2.0.yaml
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,12 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "2.0" | ||
| description: Module with two versions | ||
|
|
||
| applications: [] | ||
|
|
||
| # Deprecating both versions together moves their modulefile links into the deprecated | ||
| # area and clears the now-spent live modulefiles name folder. | ||
| deprecated: true |
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,3 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: {} |
8 changes: 8 additions & 0 deletions
8
tests/configs/valid/multi-version-explicit-default/example-module-multi/1.0.yaml
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,8 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "1.0" | ||
| description: Module with two versions, used to exercise explicit default selection | ||
|
|
||
| applications: [] |
8 changes: 8 additions & 0 deletions
8
tests/configs/valid/multi-version-explicit-default/example-module-multi/2.0.yaml
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,8 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-multi | ||
| version: "2.0" | ||
| description: Module with two versions, used to exercise explicit default selection | ||
|
|
||
| applications: [] |
5 changes: 5 additions & 0 deletions
5
tests/configs/valid/multi-version-explicit-default/settings.yaml
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,5 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| # Pin the default to 1.0 even though 2.0 is present and would be auto-selected. | ||
| default_versions: | ||
| example-module-multi: "1.0" |
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,14 @@ | ||
| from pathlib import Path | ||
|
|
||
| from conftest import run_cli | ||
|
|
||
|
|
||
| def test_sync_builds_real_sif_file(configs: Path, tmp_path: Path) -> None: | ||
| # The golden-master test stubs the apptainer pull, so this is the only test that | ||
| # exercises a real one. It needs apptainer installed and network access to ghcr.io; | ||
| # a missing binary fails the test (via run_cli) rather than skipping it, by design. | ||
| run_cli("sync", "--from-scratch", tmp_path, configs / "valid" / "apptainer-pull") | ||
|
|
||
| sif_files = list(tmp_path.glob("**/*.sif")) | ||
| assert sif_files, "sync did not produce a .sif file" | ||
| assert all(f.stat().st_size > 0 for f in sif_files), "produced .sif file is empty" | ||
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,103 @@ | ||
| import hashlib | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import yaml | ||
|
|
||
| from conftest import run_cli | ||
| from deploy_tools.app_builder import AppBuilderError | ||
|
|
||
| # A small payload served as a local file:// "download" source, so the binary builder's | ||
| # real urlretrieve and hashing run with no network access. | ||
| BINARY_CONTENT = b"#!/bin/sh\necho 'hello from a binary module'\n" | ||
|
|
||
| DIGESTS = { | ||
| "sha256": hashlib.sha256(BINARY_CONTENT).hexdigest(), | ||
| "sha512": hashlib.sha512(BINARY_CONTENT).hexdigest(), | ||
| "md5": hashlib.md5(BINARY_CONTENT).hexdigest(), | ||
| } | ||
|
|
||
|
|
||
| def _write_binary_deployment( | ||
| tmp_path: Path, hash_type: str, hash_value: str | ||
| ) -> tuple[Path, Path]: | ||
| """Build a deployment root and a single binary-module config under ``tmp_path``. | ||
|
|
||
| Binary modules download from a URL and verify a hash, so the config must reference a | ||
| real file whose digest is known at test time. A committed config cannot carry such a | ||
| machine-specific ``file://`` path, so it is generated per test. | ||
|
|
||
| Args: | ||
| tmp_path: The per-test scratch directory. | ||
| hash_type: The ``hash_type`` to record in the config. | ||
| hash_value: The hash to record in the config. | ||
|
|
||
| Returns: | ||
| The ``(deployment_root, config_folder)`` pair to pass to ``sync``. | ||
| """ | ||
| source = tmp_path / "downloads" / "example-tool" | ||
| source.parent.mkdir() | ||
| source.write_bytes(BINARY_CONTENT) | ||
|
|
||
| config_folder = tmp_path / "config" | ||
| module_dir = config_folder / "example-binary" | ||
| module_dir.mkdir(parents=True) | ||
| (config_folder / "settings.yaml").write_text("default_versions: {}\n") | ||
|
|
||
| release = { | ||
| "module": { | ||
| "name": "example-binary", | ||
| "version": "1.0", | ||
| "description": "Single binary module for builder coverage", | ||
| "applications": [ | ||
| { | ||
| "app_type": "binary", | ||
| "name": "example-tool", | ||
| "url": source.as_uri(), | ||
| "hash": hash_value, | ||
| "hash_type": hash_type, | ||
| } | ||
| ], | ||
| } | ||
| } | ||
| (module_dir / "1.0.yaml").write_text(yaml.safe_dump(release)) | ||
|
|
||
| deployment_root = tmp_path / "deployment" | ||
| deployment_root.mkdir() | ||
| return deployment_root, config_folder | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("hash_type", ["sha256", "sha512", "md5"]) | ||
| def test_sync_builds_binary_with_hash_check(tmp_path: Path, hash_type: str) -> None: | ||
| # Each supported algorithm should validate the download and deploy an executable | ||
| # binary entrypoint with the original contents. | ||
| deployment_root, config_folder = _write_binary_deployment( | ||
| tmp_path, hash_type, DIGESTS[hash_type] | ||
| ) | ||
| run_cli("sync", "--from-scratch", deployment_root, config_folder) | ||
|
|
||
| binary = deployment_root / "modules/example-binary/1.0/entrypoints/example-tool" | ||
| assert binary.read_bytes() == BINARY_CONTENT | ||
| assert binary.stat().st_mode & 0o111, "deployed binary is not executable" | ||
|
|
||
|
|
||
| def test_sync_builds_binary_without_hash_check(tmp_path: Path) -> None: | ||
| # hash_type "none" skips verification; the binary is still downloaded and deployed. | ||
| deployment_root, config_folder = _write_binary_deployment(tmp_path, "none", "") | ||
| run_cli("sync", "--from-scratch", deployment_root, config_folder) | ||
|
|
||
| binary = deployment_root / "modules/example-binary/1.0/entrypoints/example-tool" | ||
| assert binary.read_bytes() == BINARY_CONTENT | ||
|
|
||
|
|
||
| def test_sync_rejects_binary_with_wrong_hash(tmp_path: Path) -> None: | ||
| # A digest that does not match the download must fail the build rather than deploy | ||
| # an unverified binary. | ||
| deployment_root, config_folder = _write_binary_deployment( | ||
| tmp_path, "sha256", "0" * 64 | ||
| ) | ||
| with pytest.raises( | ||
| AppBuilderError, | ||
| match="Downloaded Binary .*/downloads/example-tool hash check failed", | ||
| ): | ||
| run_cli("sync", "--from-scratch", deployment_root, config_folder) |
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,19 @@ | ||
| import pytest | ||
|
|
||
| from deploy_tools.external_tools import ExternalToolError, run_command | ||
|
|
||
|
|
||
| def test_run_command_reports_missing_tool() -> None: | ||
| # A required external tool that is not installed must surface as a clean | ||
| # ExternalToolError naming the tool, not a raw FileNotFoundError traceback. | ||
| with pytest.raises(ExternalToolError, match="deploy-tools-no-such-binary"): | ||
| run_command(["deploy-tools-no-such-binary"]) | ||
|
|
||
|
|
||
| def test_run_command_reports_failed_tool() -> None: | ||
| # With check=True, a non-zero exit is reported as an ExternalToolError rather than a | ||
| # raw CalledProcessError. | ||
| with pytest.raises( | ||
| ExternalToolError, match="External tool 'bash' failed with exit status 3" | ||
| ): | ||
| run_command(["bash", "-c", "exit 3"], check=True) |
Oops, something went wrong.
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.