Skip to content

Commit b56bc70

Browse files
test(api): cover untyped nodes that only declare additionalProperties
An untyped node with structural additionalProperties is inferred as an object, like one with properties. The test now refuses a scalar there and a mistyped map value, with a valid map as the control, so dropping that branch of the inference fails it. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent 18f95b3 commit b56bc70

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎pkg/reservation/evaluator_test.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ func TestEvaluateChecksUntypedSchemasByShape(t *testing.T) {
330330
// with items as an array, so the type check must as well.
331331
s, err := defaulting.BuildSchema(`{"type":"object","properties":{
332332
"resources":{"properties":{"cpu":{"type":"integer"}}},
333-
"disks":{"items":{"type":"string"}}}}`)
333+
"disks":{"items":{"type":"string"}},
334+
"labels":{"additionalProperties":{"type":"string"}}}}`)
334335
if err != nil {
335336
t.Fatal(err)
336337
}
@@ -340,14 +341,15 @@ func TestEvaluateChecksUntypedSchemasByShape(t *testing.T) {
340341
if err != nil {
341342
t.Fatal(err)
342343
}
343-
for _, raw := range []string{`{"resources": "invalid"}`, `{"resources": {"cpu": "2"}}`, `{"disks": "a"}`, `{"disks": [1]}`} {
344+
for _, raw := range []string{`{"resources": "invalid"}`, `{"resources": {"cpu": "2"}}`, `{"disks": "a"}`, `{"disks": [1]}`, `{"labels": "a"}`, `{"labels": {"a": 1}}`} {
344345
if got, err := ev.EvaluateJSON([]byte(raw), env); err == nil {
345346
t.Errorf("%s: expected an error, got %v", raw, got)
346347
}
347348
}
348349
for raw, want := range map[string]ResourceList{
349350
`{"resources": {"cpu": 2}}`: rl("cpu", "2"),
350351
`{"disks": ["a"]}`: rl("cpu", "1"),
352+
`{"labels": {"a": "b"}}`: rl("cpu", "1"),
351353
} {
352354
got, err := ev.EvaluateJSON([]byte(raw), env)
353355
if err != nil {

0 commit comments

Comments
 (0)