feat(validation): name a keyed collection as such when a list is given
This commit is contained in:
@@ -78,7 +78,8 @@ class _Validator:
|
|||||||
self.errors.append(f"{path}: expected bool or dict, got {_kind(value)}")
|
self.errors.append(f"{path}: expected bool or dict, got {_kind(value)}")
|
||||||
return
|
return
|
||||||
if not TYPES[kind](value):
|
if not TYPES[kind](value):
|
||||||
self.errors.append(f"{path}: expected {kind}, got {_kind(value)}")
|
keyed = len(spec.get("options", {})) == 1 and next(iter(spec["options"])).startswith("<")
|
||||||
|
self.errors.append(f"{path}: expected {'dict keyed by name' if keyed else kind}, got {_kind(value)}")
|
||||||
return
|
return
|
||||||
if "choices" in spec and value not in spec["choices"]:
|
if "choices" in spec and value not in spec["choices"]:
|
||||||
shown = "" if spec.get("no_log") else f", got {value!r}"
|
shown = "" if spec.get("no_log") else f", got {value!r}"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ inputs_fixtures:
|
|||||||
name: web01
|
name: web01
|
||||||
users:
|
users:
|
||||||
- name: alice
|
- name: alice
|
||||||
expect: ["fixture.users: expected dict, got list"]
|
expect: ["fixture.users: expected dict keyed by name, got list"]
|
||||||
|
|
||||||
- name: comma-string-for-list
|
- name: comma-string-for-list
|
||||||
value:
|
value:
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ users_fixtures:
|
|||||||
- name: ops
|
- name: ops
|
||||||
password: pw
|
password: pw
|
||||||
expect:
|
expect:
|
||||||
fail: "system.users: expected dict, got list"
|
fail: "system.users: expected dict keyed by name, got list"
|
||||||
|
|
||||||
- name: list-rejected-precomputed
|
- name: list-rejected-precomputed
|
||||||
precomputed: true
|
precomputed: true
|
||||||
@@ -61,7 +61,7 @@ users_fixtures:
|
|||||||
- name: ops
|
- name: ops
|
||||||
password: pw
|
password: pw
|
||||||
expect:
|
expect:
|
||||||
fail: "system.users: expected dict, got list"
|
fail: "system.users: expected dict keyed by name, got list"
|
||||||
|
|
||||||
- name: scalar-entry-rejected
|
- name: scalar-entry-rejected
|
||||||
system:
|
system:
|
||||||
|
|||||||
Reference in New Issue
Block a user