apiextensions: add unit test for x-kubernetes-preserve-unknown-fields with additionalProperties

This commit is contained in:
Dr. Stefan Schimanski 2019-06-10 18:22:56 +02:00
parent 5d000b1339
commit a03330fbeb

View File

@ -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": {}
}