-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #706 from vmware-tanzu/assert-one-of
Add `one_of()` / `one_of=` — a value is within an enumeration
- Loading branch information
Showing
15 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/max=/invalid-when-value-greater-than-max.tpltest
This file contains 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,7 @@ | ||
#@assert/validate max=10 | ||
foo: 11 | ||
|
||
+++ | ||
|
||
ERR: | ||
- "foo" (stdin:2) requires "a value less than or equal to 10"; fail: 11 is more than 10 (by stdin:1) |
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/max_len=/invalid-when-length-greater-than-max.tpltest
This file contains 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,7 @@ | ||
#@assert/validate max_len=5 | ||
value: "123456" | ||
|
||
+++ | ||
|
||
ERR: | ||
- "value" (stdin:2) requires "length less than or equal to 5"; fail: length of 6 is more than 5 (by stdin:1) |
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/min=/invalid-when-value-less-than-min.tpltest
This file contains 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,7 @@ | ||
#@assert/validate min=10 | ||
value: 9 | ||
|
||
+++ | ||
|
||
ERR: | ||
- "value" (stdin:2) requires "a value greater or equal to 10"; fail: 9 is less than 10 (by stdin:1) |
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/min_len=/invalid-when-length-is-less-than-min.tpltest
This file contains 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,7 @@ | ||
#@assert/validate min_len=5 | ||
value: "1234" | ||
|
||
+++ | ||
|
||
ERR: | ||
- "value" (stdin:2) requires "length greater or equal to 5"; fail: length of 4 is less than 5 (by stdin:1) |
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/not_null=/invalid-when-value-is-null.tpltest
This file contains 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,7 @@ | ||
#@assert/validate not_null=True | ||
value: null | ||
|
||
+++ | ||
|
||
ERR: | ||
- "value" (stdin:2) requires "not null"; fail: value is null (by stdin:1) |
9 changes: 9 additions & 0 deletions
9
pkg/validations/filetests/one_not_null=/invalid-when-more-than-one-is-not-null.tpltest
This file contains 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,9 @@ | ||
#@assert/validate one_not_null=True | ||
config: | ||
foo: "" | ||
bar: "" | ||
|
||
+++ | ||
|
||
ERR: | ||
- "config" (stdin:2) requires "exactly one child not null"; check: multiple values are not null ["foo" "bar"] (by stdin:1) |
7 changes: 7 additions & 0 deletions
7
pkg/validations/filetests/one_of=/invalid-when-value-not-in-enum.tpltest
This file contains 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,7 @@ | ||
#@assert/validate one_of=["debug","info","warning","error","fatal"] | ||
foo: critical | ||
|
||
+++ | ||
|
||
ERR: | ||
- "foo" (stdin:2) requires "one of"; fail: critical not in ["debug", "info", "warning", "error", "fatal"] (by stdin:1) |
6 changes: 6 additions & 0 deletions
6
pkg/validations/filetests/one_of=/rejects-non-sequence-arg.tpltest
This file contains 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,6 @@ | ||
#@assert/validate one_of="one,two,three" | ||
foo: two | ||
|
||
+++ | ||
|
||
ERR: Invalid @assert/validate annotation - expected keyword argument one_of to be a sequence, but was string |
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
pkg/yamltemplate/filetests/ytt-library/assert/one_of/err-args-too-few.tpltest
This file contains 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,14 @@ | ||
#@ load("@ytt:assert", "assert") | ||
|
||
|
||
one_of: #@ assert.try_to(lambda: assert.one_of()) | ||
check: #@ assert.try_to(lambda: assert.one_of(1,2).check()) | ||
|
||
+++ | ||
|
||
one_of: | ||
- null | ||
- 'assert.one_of: got 0 arguments, want at least 1' | ||
check: | ||
- null | ||
- function lambda missing 1 argument (val) |
9 changes: 9 additions & 0 deletions
9
pkg/yamltemplate/filetests/ytt-library/assert/one_of/err-args-too-many.tpltest
This file contains 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,9 @@ | ||
#@ load("@ytt:assert", "assert") | ||
|
||
check: #@ assert.try_to(lambda: assert.one_of([1,2]).check(1,2)) | ||
|
||
+++ | ||
|
||
check: | ||
- null | ||
- function lambda accepts 1 positional argument (2 given) |
31 changes: 31 additions & 0 deletions
31
pkg/yamltemplate/filetests/ytt-library/assert/one_of/main.tpltest
This file contains 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,31 @@ | ||
#@ load("@ytt:assert", "assert") | ||
|
||
pass: | ||
list: #@ assert.one_of(["aws", "azure", "vsphere"]).check("azure") | ||
tuple: #@ assert.one_of(( "aws", "azure", "vsphere" )).check("azure") | ||
heterogeneous: #@ assert.one_of("aws", 4, False, {"azure": "vsphere"}).check({"azure": "vsphere"}) | ||
positional_args: #@ assert.one_of("aws", "azure", "vsphere").check("azure") | ||
fail: | ||
not_in_enum: #@ assert.try_to(lambda: assert.one_of("aws", "azure", "vsphere").check("not-in-set")) | ||
enum_not_a_sequence: | ||
int: #@ assert.try_to(lambda: assert.one_of(4)) | ||
string: #@ assert.try_to(lambda: assert.one_of("aws,azure,vsphere")) | ||
|
||
+++ | ||
|
||
pass: | ||
list: true | ||
tuple: true | ||
heterogeneous: true | ||
positional_args: true | ||
fail: | ||
not_in_enum: | ||
- null | ||
- 'fail: not-in-set not in ["aws", "azure", "vsphere"]' | ||
enum_not_a_sequence: | ||
int: | ||
- null | ||
- 'assert.one_of: expected a sequence, but was a ''int''' | ||
string: | ||
- null | ||
- 'assert.one_of: expected a sequence, but was a ''string''' |
This file contains 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