From a03330fbebdd14f15f74f15f25fdf5741d69c0dc Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 10 Jun 2019 18:22:56 +0200 Subject: [PATCH] apiextensions: add unit test for x-kubernetes-preserve-unknown-fields with additionalProperties --- .../schema/pruning/algorithm_test.go | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/pruning/algorithm_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/pruning/algorithm_test.go index 58aba203490..4ddf9301144 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/pruning/algorithm_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/pruning/algorithm_test.go @@ -85,7 +85,13 @@ func TestPrune(t *testing.T) { "pruning": {"unspecified": "bar"}, "preserving": {"unspecified": "bar"} }, - "preservingAdditionalProperties": { + "preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": { + "foo": { + "specified": {"unspecified":"bar"}, + "unspecified": "bar" + } + }, + "preservingAdditionalPropertiesKeyPruneValues": { "foo": { "specified": {"unspecified":"bar"}, "unspecified": "bar" @@ -123,7 +129,8 @@ func TestPrune(t *testing.T) { }, }, }, - "preservingAdditionalProperties": { + "preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": { + // this x-kubernetes-preserve-unknown-fields is not inherited by the schema inside of additionalProperties Extensions: structuralschema.Extensions{XPreserveUnknownFields: true}, Generic: structuralschema.Generic{ Type: "object", @@ -137,6 +144,19 @@ func TestPrune(t *testing.T) { }, }, }, + "preservingAdditionalPropertiesKeyPruneValues": { + Generic: structuralschema.Generic{ + Type: "object", + AdditionalProperties: &structuralschema.StructuralOrBool{ + Structural: &structuralschema.Structural{ + Generic: structuralschema.Generic{Type: "object"}, + Properties: map[string]structuralschema.Structural{ + "specified": {Generic: structuralschema.Generic{Type: "object"}}, + }, + }, + }, + }, + }, }, }, expected: ` { @@ -154,7 +174,12 @@ func TestPrune(t *testing.T) { "pruning": {}, "preserving": {"unspecified": "bar"} }, - "preservingAdditionalProperties": { + "preservingAdditionalPropertiesNotInheritingXPreserveUnknownFields": { + "foo": { + "specified": {} + } + }, + "preservingAdditionalPropertiesKeyPruneValues": { "foo": { "specified": {} }