Skip to content

Commit

Permalink
Add test excluding named validations when when= is present for json s…
Browse files Browse the repository at this point in the history
…chema

Signed-off-by: Mathias Petermann <mathias.petermann@gmail.com>
  • Loading branch information
peschmae committed Apr 20, 2024
1 parent 162f40c commit a29ae1f
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions pkg/cmd/template/schema_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,9 @@ foo:
#@schema/validation min=0, max=100
range_key: 0
#@schema/validation min=-1.1, max=100.1
range_float_key: 2.2
#@schema/default 10
#@schema/validation min=0
min_key: 0
Expand All @@ -1714,11 +1717,22 @@ foo:
#@schema/validation min_len=1, max_len=10
string_key: ""
#@schema/validation min_len=3, max_len=4
array_key:
- ""
#@schema/validation min_len=2, max_len=5
map_key: {}
#@schema/validation one_of=[1,2,3]
one_of_integers: 1
#@schema/validation one_of=["one", "two", "three"]
one_of_strings: "one"
#@schema/type any=True
#@schema/validation one_of=["one", 2, 3.3, {}]
one_of_mixed: "one"
`
expected := `$schema: https://json-schema.org/draft/2020-12/schema
$id: https://example.biz/schema/ytt/data-values.json
Expand All @@ -1735,6 +1749,12 @@ properties:
default: 10
minimum: 0
maximum: 100
range_float_key:
type: number
format: float
default: 2.2
minimum: -1.1
maximum: 100.1
min_key:
type: integer
default: 10
Expand All @@ -1748,6 +1768,20 @@ properties:
default: ""
minLength: 1
maxLength: 10
array_key:
type: array
items:
type: string
default: ""
default: []
minItems: 3
maxItems: 4
map_key:
type: object
additionalProperties: false
properties: {}
minProperties: 2
maxProperties: 5
one_of_integers:
type: integer
default: 1
Expand All @@ -1762,6 +1796,20 @@ properties:
- one
- two
- three
one_of_mixed:
type:
- "null"
- string
- number
- object
- array
- boolean
default: one
enum:
- one
- 2
- 3.3
- {}
`

filesToProcess := files.NewSortedFiles([]*files.File{
Expand All @@ -1771,6 +1819,64 @@ properties:
assertSucceedsDocSet(t, filesToProcess, expected, opts)
})

t.Run("not including named validations when when= is present", func(t *testing.T) {
opts := cmdtpl.NewOptions()
opts.DataValuesFlags.InspectSchema = true
opts.RegularFilesSourceOpts.OutputType.Types = []string{"json-schema"}

schemaYAML := `#@data/values-schema
---
foo:
#@schema/validation min=0, max=100, when=lambda: False
range_key: 0
#@schema/default 10
#@schema/validation min=0, when=lambda: False
min_key: 0
#@schema/default 10
#@schema/validation max=100, when=lambda: False
max_key: 0
#@schema/validation min_len=1, max_len=10, when=lambda: False
string_key: ""
#@schema/validation one_of=[1,2,3], when=lambda: False
one_of_integers: 1
`
expected := `$schema: https://json-schema.org/draft/2020-12/schema
$id: https://example.biz/schema/ytt/data-values.json
description: Schema for data values, generated by ytt
type: object
additionalProperties: false
properties:
foo:
type: object
additionalProperties: false
properties:
range_key:
type: integer
default: 0
min_key:
type: integer
default: 10
max_key:
type: integer
default: 10
string_key:
type: string
default: ""
one_of_integers:
type: integer
default: 1
`

filesToProcess := files.NewSortedFiles([]*files.File{
files.MustNewFileFromSource(files.NewBytesSource("schema.yml", []byte(schemaYAML))),
})

assertSucceedsDocSet(t, filesToProcess, expected, opts)
})
}

func assertSucceedsDocSet(t *testing.T, filesToProcess []*files.File, expectedOut string, opts *cmdtpl.Options) {
Expand Down

0 comments on commit a29ae1f

Please sign in to comment.