-
Notifications
You must be signed in to change notification settings - Fork 0
Draft: Add command behaviour tests #60
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
Changes from all commits
9e54a3d
c169842
a08460b
04c3d6c
bd94f8b
06cbd0c
8f8ca4b
9642087
5f243d7
0fc31b4
6f85eff
662c578
3662b01
4516b07
0a2bf29
6db1cb6
2c4d493
b7f52a9
c5ce9ad
3b3e043
a5b1673
db9aa4b
5f5fcaa
76a29a6
3352347
5081ea8
d7c76e8
df673cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| import yaml | ||
| from pydantic import BaseModel | ||
| from pydantic import ValidationError as PydanticValidationError | ||
|
|
||
| from ..errors import DeployToolsError | ||
| from .deployment import ( | ||
|
|
@@ -67,18 +68,20 @@ def _load_release(path: Path) -> Release: | |
| if path.is_dir() or not path.suffix == YAML_FILE_SUFFIX: | ||
| raise LoadError(f"Unexpected file in configuration directory:\n{path}") | ||
|
|
||
| with open(path) as f: | ||
| return load_from_yaml(Release, f) | ||
| try: | ||
| with open(path) as f: | ||
| return load_from_yaml(Release, f) | ||
| except (OSError, yaml.YAMLError, PydanticValidationError, TypeError) as exc: | ||
| # Include exc: under the top-level handler the traceback (and chained cause) is | ||
| # suppressed, so the failing field is only visible if surfaced in the message. | ||
| raise LoadError(f"Module configuration is invalid:\n{path}\n{exc}") from exc | ||
|
|
||
|
|
||
| def _check_filepath_matches(version_path: Path, module: Module) -> None: | ||
| """Ensure the Module's file path (in config folder) matches the metadata. | ||
|
|
||
| It should be the Module's name and version as /<config_folder>/<name>/<version>.yaml | ||
| """ | ||
| if version_path.is_dir() and version_path.suffix == YAML_FILE_SUFFIX: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code as _load_release() already checks if path.is_dir() |
||
| raise LoadError(f"Module directory has incorrect suffix:\n{version_path}") | ||
|
|
||
| if not module.name == version_path.parent.name: | ||
| raise LoadError( | ||
| f"Module name {module.name} does not match path:\n{version_path}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import io | ||
| import logging | ||
|
|
||
| from git import Repo | ||
| import yaml | ||
| from git import BadName, Repo | ||
| from pydantic import ValidationError as PydanticValidationError | ||
|
|
||
| from .errors import DeployToolsError | ||
| from .layout import Layout | ||
|
|
@@ -54,14 +56,25 @@ def load_snapshot(layout: Layout, from_scratch: bool = False) -> Deployment: | |
| ) | ||
|
|
||
| logger.debug("Loading snapshot: %s", layout.deployment_snapshot_path) | ||
| with open(layout.deployment_snapshot_path) as f: | ||
| return load_from_yaml(Deployment, f) | ||
| try: | ||
| with open(layout.deployment_snapshot_path) as f: | ||
| return load_from_yaml(Deployment, f) | ||
| except (OSError, yaml.YAMLError, PydanticValidationError, TypeError) as exc: | ||
| raise SnapshotError( | ||
| f"Deployment snapshot could not be read:\n{layout.deployment_snapshot_path}" | ||
| ) from exc | ||
|
|
||
|
|
||
| def load_snapshot_from_ref(layout: Layout, ref: str) -> Deployment: | ||
| """Load the deployment snapshot from the given git ref of the deployment area.""" | ||
| logger.debug("Loading snapshot from ref: %s", ref) | ||
| repo = Repo(layout.deployment_root) | ||
| ref_snapshot = repo.commit(ref).tree[layout.DEPLOYMENT_SNAPSHOT_FILENAME] | ||
| with io.BytesIO(ref_snapshot.data_stream.read()) as snapshot_f: # type: ignore | ||
| return load_from_yaml(Deployment, snapshot_f) | ||
| with Repo(layout.deployment_root) as repo: | ||
| try: | ||
| ref_snapshot = repo.commit(ref).tree[layout.DEPLOYMENT_SNAPSHOT_FILENAME] | ||
| except (BadName, KeyError) as exc: | ||
| raise SnapshotError( | ||
| f"Deployment snapshot not found at git ref:\n{ref}" | ||
| ) from exc | ||
|
|
||
| with io.BytesIO(ref_snapshot.data_stream.read()) as snapshot_f: # type: ignore | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need # type: ignore ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although GitPython has type hints, it appears gitdb (a dependency) does not. I'll add a minor edit to remove the type ignore statement. This is also just an indentation change. |
||
| return load_from_yaml(Deployment, snapshot_f) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Test configurations | ||
|
|
||
| Sample `deploy-tools` configuration folders used by the test suite, grouped by purpose: | ||
|
|
||
| - **`golden-master/`** — the `01-initial` … `06-removed` lifecycle sequence. These are | ||
| **cumulative and ordered**: each stage is synced on top of the previous one to model a | ||
| real deployment lifecycle (only `01-initial` uses `--from-scratch`). Driven by | ||
| `test_golden_master.py` and regenerated by `generate_samples.sh`. Do not reorder or make | ||
| independent. | ||
| - **`valid/`** — standalone, self-contained configs that should deploy/validate cleanly, | ||
| each serving one focused test (e.g. `minimal`, `empty`, `multi-version-active`). | ||
| - **`invalid/`** — configs that a command must reject; each maps to a test asserting the | ||
| specific error message. | ||
|
|
||
| When adding a fixture, prefer reusing an existing one; otherwise add a single-purpose | ||
| folder under `valid/` or `invalid/`. Leave `golden-master/` to the lifecycle sequence. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Minimal shell-only module used by the validate tests | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: | ||
| example-module-shell: "2.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Minimal shell-only module used by the validate tests | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "2.0" | ||
| description: Minimal shell-only module used by the validate tests | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello | ||
|
|
||
| deprecated: true |
| 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: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| # The module name contains a dot, which MODULE_NAME_REGEX forbids; loading must fail | ||
| # with a clear LoadError that names the offending field. | ||
| module: | ||
| name: example.module.shell | ||
| version: "1.0" | ||
| description: Module with a name that violates the name constraint | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
| 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: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Module whose shell script is not valid bash | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| # 'fi' with no matching 'if' is invalid bash, so `validate --test-build` must | ||
| # reject the generated entrypoint when it runs `bash -n` over it. | ||
| script: | ||
| - fi |
| 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: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Minimal shell-only module used by the validate tests | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| # Differs from the valid/minimal baseline (echo hello) so that deploying this over | ||
| # it is an in-place modification, rejected without allow_updates / a version bump. | ||
| script: | ||
| - echo modified |
| 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: {} |
| 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: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| # The module name does not match its parent folder (wrong-folder-name), which the | ||
| # loader requires to match. | ||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Module whose name does not match its containing folder | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code (now uses git refs)