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
6 changes: 4 additions & 2 deletions rockcraft/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,18 @@ def _get_check_tag(check: Mapping[str, Any] | _BaseCheck) -> str:
return "tcp"
if isinstance(check, ExecCheck):
return "exec"
if not isinstance(check, Mapping):
raise CraftValidationError(f"Unknown check type for {check!r}.")

tags = ("http", "tcp", "exec")
check_types = check.keys() & tags
check_types = [tag for tag in tags if tag in check]
match len(check_types):
case 0:
raise CraftValidationError(
f"Must specify exactly one of {', '.join(tags)} for each check."
)
case 1:
return check_types.pop()
return check_types[0]
case _:
raise CraftValidationError(
f"Multiple check types specified ({', '.join(sorted(check_types))}). "
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import subprocess
import warnings
from pathlib import Path
from typing import cast
from typing import Any, cast

import pydantic
import pytest
Expand Down Expand Up @@ -884,7 +884,8 @@ def test_project_marshal_exec_check_emits_no_pydantic_warning():
warnings.simplefilter("always")
dumped = project.marshal()

assert dumped["checks"]["online"]["exec"]["command"] == "/bin/healthcheck"
checks = cast(dict[str, Any], dumped["checks"])
assert checks["online"]["exec"]["command"] == "/bin/healthcheck"
assert not any(
"PydanticSerializationUnexpectedValue" in str(w.message) for w in caught
)
Expand Down