Skip to content
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
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
3 changes: 3 additions & 0 deletions tests/configs/invalid/invalid-module-name/settings.yaml
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 tests/configs/invalid/name-mismatch/settings.yaml
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 tests/configs/invalid/name-mismatch/wrong-folder-name/1.0.yaml
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
13 changes: 13 additions & 0 deletions tests/configs/invalid/stray-file/example-module-shell/1.0.yaml
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 sat alongside a stray non-yaml file

applications:
- app_type: shell

name: test-shell-echo
script:
- echo hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A stray non-YAML file in a module directory. The config loader treats every entry
under a module folder as a release file, so this must be rejected with a LoadError.
3 changes: 3 additions & 0 deletions tests/configs/invalid/stray-file/settings.yaml
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 version does not match its filename (2.0.yaml), which the loader requires
# to match.
module:
name: example-module-shell
version: "1.0"
description: Module whose version does not match its filename

applications:
- app_type: shell

name: test-shell-echo
script:
- echo hello
3 changes: 3 additions & 0 deletions tests/configs/invalid/version-mismatch/settings.yaml
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: {}
9 changes: 0 additions & 9 deletions tests/test_cli.py

This file was deleted.

23 changes: 23 additions & 0 deletions tests/test_cli_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subprocess
import sys
from pathlib import Path

from deploy_tools import __version__


def test_cli_version() -> None:
cmd = [sys.executable, "-m", "deploy_tools", "--version"]
assert subprocess.check_output(cmd).decode().strip() == __version__


def test_cli_reports_domain_error_without_traceback(tmp_path: Path) -> None:
# compare on an existing area with no snapshot raises SnapshotError, a
# DeployToolsError. Run the real entry point and confirm the message is presented as
# a clean 'Error: ...' on stderr with exit 1, and no traceback is dumped.
cmd = [sys.executable, "-m", "deploy_tools", "compare", str(tmp_path)]
result = subprocess.run(cmd, capture_output=True, text=True)

assert result.returncode == 1
assert "Error:" in result.stderr
assert "snapshot not found" in result.stderr
assert "Traceback" not in result.stderr
41 changes: 41 additions & 0 deletions tests/test_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path

import pytest

from conftest import run_cli
from deploy_tools.models.save_and_load import LoadError

# Configs whose on-disk layout is malformed: loading must fail with a clear LoadError
# before any validation logic runs. Each maps a folder under configs/invalid to a
# substring expected in the error.
MALFORMED_CONFIGS = [
("stray-file", "Unexpected file in configuration directory:\n.*/README.txt"),
("name-mismatch", "Module name example-module-shell does not match path"),
("version-mismatch", "Module version 1.0 does not match path"),
]


@pytest.mark.parametrize("config_name, message", MALFORMED_CONFIGS)
def test_load_rejects_malformed_config_layout(
tmp_path: Path, configs: Path, config_name: str, message: str
) -> None:
with pytest.raises(LoadError, match=message):
run_cli(
"validate", "--from-scratch", tmp_path, configs / "invalid" / config_name
)


def test_load_surfaces_invalid_field_in_error(tmp_path: Path, configs: Path) -> None:
# A config that fails model validation must raise a clean LoadError that names the
# offending field; the top-level handler hides the traceback, so the field detail is
# only visible if carried in the message.
with pytest.raises(LoadError) as exc_info:
run_cli(
"validate",
"--from-scratch",
tmp_path,
configs / "invalid" / "invalid-module-name",
)
message = str(exc_info.value)
assert "Module configuration is invalid" in message
assert "module.name" in message
Loading