-
Notifications
You must be signed in to change notification settings - Fork 0
Add validation tests #63
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa85841
Add behavioural tests for validate command
MJGaughran b536836
Add validation checks for handling initially-deprecated modules
MJGaughran 9579ac3
Add dedicated unit tests for default version logic
MJGaughran 6f97291
Move minimal test config to location consistent with others
MJGaughran 819bbf7
Improve names of configuration folders
MJGaughran 270ab73
Reduce irrelevant parameters in configuration
MJGaughran dd2f5aa
Add tests for validation edge cases
MJGaughran 7f73803
Use more specific pytest.raises matches for test_validate.py
MJGaughran f67c14d
Reword test config descriptions to clarify use
MJGaughran ec30347
Use more specific pytest.raises matches in test_default_versions.py
MJGaughran 5fb0dae
Trim module docstring for test_default_versions.py
MJGaughran 0506350
Make test build check explicit in test_validate.py
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
13 changes: 13 additions & 0 deletions
13
tests/configs/invalid/default-version-not-deployed/example-module-shell/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,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 with a single shell application | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
4 changes: 4 additions & 0 deletions
4
tests/configs/invalid/default-version-not-deployed/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,4 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: | ||
| example-module-shell: "2.0" |
13 changes: 13 additions & 0 deletions
13
tests/configs/invalid/deprecated-on-creation/example-module-shell/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,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 with a single shell application | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello |
15 changes: 15 additions & 0 deletions
15
tests/configs/invalid/deprecated-on-creation/example-module-shell/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,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 with a single shell application | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello | ||
|
|
||
| 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: {} |
15 changes: 15 additions & 0 deletions
15
tests/configs/invalid/invalid-shell-script/example-module-shell/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,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 |
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: {} |
15 changes: 15 additions & 0 deletions
15
tests/configs/invalid/modified-without-allow-updates/example-module-shell/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,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 with a single shell application | ||
|
|
||
| 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 |
3 changes: 3 additions & 0 deletions
3
tests/configs/invalid/modified-without-allow-updates/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,3 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/deployment-settings.json | ||
|
|
||
| default_versions: {} |
15 changes: 15 additions & 0 deletions
15
tests/configs/invalid/no-eligible-default/example-module-shell/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,15 @@ | ||
| # yaml-language-server: $schema=/workspaces/deploy-tools/src/deploy_tools/models/schemas/release.json | ||
|
|
||
| module: | ||
| name: example-module-shell | ||
| version: "1.0" | ||
| description: Shell module excluded from defaults with no eligible fallback | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo hello | ||
|
|
||
| exclude_from_defaults: 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: {} |
3 changes: 3 additions & 0 deletions
3
tests/configs/invalid/removed-without-deprecation/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,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/invalid/unknown-dependency/example-module-base/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-base | ||
| version: "1.0" | ||
| description: Base module that the dependent module references | ||
|
|
||
| applications: [] |
12 changes: 12 additions & 0 deletions
12
tests/configs/invalid/unknown-dependency/example-module-dependent/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-dependent | ||
| version: "1.0" | ||
| description: References a version of example-module-base that does not exist | ||
|
|
||
| dependencies: | ||
| - name: example-module-base | ||
| version: "9.9" | ||
|
|
||
| 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: {} |
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,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 with a single shell application | ||
|
|
||
| applications: | ||
| - app_type: shell | ||
|
|
||
| name: test-shell-echo | ||
| script: | ||
| - echo 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,127 @@ | ||
| """Unit tests for default-version selection. | ||
|
|
||
| These call the function directly rather than through the CLI. Here that is to isolate | ||
| pure, non-trivial logic (e.g. natsort ordering of non-SemVer versions). | ||
| """ | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
| import pytest | ||
|
|
||
| from deploy_tools.models.deployment import ( | ||
| Deployment, | ||
| DeploymentSettings, | ||
| ReleasesByNameAndVersion, | ||
| ) | ||
| from deploy_tools.models.module import Module, Release | ||
| from deploy_tools.validate import ValidationError, validate_default_versions | ||
|
|
||
|
|
||
| def _release( | ||
| name: str, version: str, *, deprecated: bool = False, excluded: bool = False | ||
| ) -> Release: | ||
| """Build a minimal Release with no applications, for selection tests.""" | ||
| return Release( | ||
| module=Module( | ||
| name=name, | ||
| version=version, | ||
| applications=[], | ||
| exclude_from_defaults=excluded, | ||
| ), | ||
| deprecated=deprecated, | ||
| ) | ||
|
|
||
|
|
||
| def _deployment( | ||
| *releases: Release, default_versions: dict[str, str] | None = None | ||
| ) -> Deployment: | ||
| """Assemble a Deployment from loose Releases and optional explicit defaults.""" | ||
| by_name: ReleasesByNameAndVersion = defaultdict(dict) | ||
| for release in releases: | ||
| by_name[release.module.name][release.module.version] = release | ||
|
|
||
| return Deployment( | ||
| settings=DeploymentSettings(default_versions=default_versions or {}), | ||
| releases=by_name, | ||
| ) | ||
|
|
||
|
|
||
| def test_auto_selects_latest_version_by_natsort() -> None: | ||
| # natsort, not string ordering: "10.0" must beat "2.0" (which sorts last lexically). | ||
| deployment = _deployment( | ||
| _release("mod", "1.0"), | ||
| _release("mod", "2.0"), | ||
| _release("mod", "10.0"), | ||
| ) | ||
| assert validate_default_versions(deployment) == {"mod": "10.0"} | ||
|
|
||
|
|
||
| def test_prerelease_sorts_before_final_release() -> None: | ||
| # The documented non-SemVer case: "1.2rc1" must come before "1.2", so the final | ||
| # release is chosen as default over its own release candidate. | ||
| deployment = _deployment( | ||
| _release("mod", "1.2rc1"), | ||
| _release("mod", "1.2"), | ||
| ) | ||
| assert validate_default_versions(deployment) == {"mod": "1.2"} | ||
|
|
||
|
|
||
| def test_excluded_versions_are_not_auto_selected() -> None: | ||
| # The highest version opts out of defaults, so the next-highest is chosen instead. | ||
| deployment = _deployment( | ||
| _release("mod", "1.0"), | ||
| _release("mod", "2.0", excluded=True), | ||
| ) | ||
| assert validate_default_versions(deployment) == {"mod": "1.0"} | ||
|
|
||
|
|
||
| def test_deprecated_versions_are_not_auto_selected() -> None: | ||
| # Deprecated releases are excluded from the deployed set, so a higher deprecated | ||
| # version must not become the default over a lower active one. | ||
| deployment = _deployment( | ||
| _release("mod", "1.0"), | ||
| _release("mod", "2.0", deprecated=True), | ||
| ) | ||
| assert validate_default_versions(deployment) == {"mod": "1.0"} | ||
|
|
||
|
|
||
| def test_explicit_default_is_preserved_over_auto_selection() -> None: | ||
| # An explicit default wins even when a higher version exists. | ||
| deployment = _deployment( | ||
| _release("mod", "1.0"), | ||
| _release("mod", "2.0"), | ||
| default_versions={"mod": "1.0"}, | ||
| ) | ||
| assert validate_default_versions(deployment) == {"mod": "1.0"} | ||
|
|
||
|
|
||
| def test_explicit_default_for_nonexistent_version_raises() -> None: | ||
| # Pointing the default at a version that will not be deployed is rejected. | ||
| deployment = _deployment( | ||
| _release("mod", "1.0"), | ||
| default_versions={"mod": "9.9"}, | ||
| ) | ||
| with pytest.raises(ValidationError, match="Unable to configure mod/9.9 as default"): | ||
| validate_default_versions(deployment) | ||
|
|
||
|
|
||
| def test_explicit_default_for_deprecated_version_raises() -> None: | ||
| # A deprecated version is not in the deployed set, so it cannot be an explicit | ||
| # default either. | ||
| deployment = _deployment( | ||
| _release("mod", "1.0", deprecated=True), | ||
| default_versions={"mod": "1.0"}, | ||
| ) | ||
| with pytest.raises(ValidationError, match="Unable to configure mod/1.0 as default"): | ||
| validate_default_versions(deployment) | ||
|
|
||
|
|
||
| def test_all_versions_excluded_raises() -> None: | ||
| # With every version opting out and no explicit default, there is no eligible | ||
| # version to make default. | ||
| deployment = _deployment(_release("mod", "1.0", excluded=True)) | ||
| with pytest.raises( | ||
| ValidationError, | ||
| match="every version for name: mod has set exclude_from_defaults", | ||
| ): | ||
| validate_default_versions(deployment) | ||
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.