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
2 changes: 1 addition & 1 deletion deckhouse/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def deny(self, message: typing.Union[str, None] = None):
self.collect(response)

def error(self, message: str):
self.collect({"allowed": False, message: f"Internal webhook error: {message}"})
self.collect({"allowed": False, "message": f"Internal webhook error: {message}"})
26 changes: 26 additions & 0 deletions tests/validations_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from deckhouse import hook


def run(handler):
return hook.testrun(handler).validations.data


def test_allow():
assert run(lambda ctx: ctx.output.validations.allow()) == [{"allowed": True}]


def test_allow_with_warnings():
data = run(lambda ctx: ctx.output.validations.allow("first", "second"))
assert data == [{"allowed": True, "warnings": ("first", "second")}]


def test_deny():
data = run(lambda ctx: ctx.output.validations.deny("not allowed"))
assert data == [{"allowed": False, "message": "not allowed"}]


def test_error_is_a_denial_with_the_message():
# shell-operator reads the reason from "message"; any other key is dropped and the
# requester sees a denial without a reason.
data = run(lambda ctx: ctx.output.validations.error("snapshot is missing"))
assert data == [{"allowed": False, "message": "Internal webhook error: snapshot is missing"}]
Loading