@@ -34,8 +34,8 @@ func TestSchemaDeclType(t *testing.T) {
34
34
if cust .TypeName () != "object" {
35
35
t .Errorf ("incorrect type name, got %v, wanted object" , cust .TypeName ())
36
36
}
37
- if len (cust .Fields ) != 4 {
38
- t .Errorf ("incorrect number of fields, got %d, wanted 4 " , len (cust .Fields ))
37
+ if len (cust .Fields ) != 5 {
38
+ t .Errorf ("incorrect number of fields, got %d, wanted 5 " , len (cust .Fields ))
39
39
}
40
40
for _ , f := range cust .Fields {
41
41
prop , found := ts .Properties [f .Name ]
@@ -70,6 +70,13 @@ func TestSchemaDeclType(t *testing.T) {
70
70
}
71
71
}
72
72
}
73
+ if prop .ValueValidation != nil && prop .ValueValidation .MaxLength != nil {
74
+ if f .Type .MaxElements != 4 * (* prop .ValueValidation .MaxLength ) {
75
+ // When converting maxLength to maxElements, it's based on the number of bytes.]
76
+ // Worst case is that one rune is 4 bytes, so maxElements should be 4x maxLength.
77
+ t .Errorf ("field maxElements does not match property 4x maxLength. field: %s, maxElements: %d, maxLength: %d" , f .Name , f .Type .MaxElements , * prop .ValueValidation .MaxLength )
78
+ }
79
+ }
73
80
}
74
81
if ts .ValueValidation != nil {
75
82
for _ , name := range ts .ValueValidation .Required {
@@ -137,6 +144,7 @@ func testSchema() *schema.Structural {
137
144
// properties:
138
145
// name:
139
146
// type: string
147
+ // maxLength: 256
140
148
// nested:
141
149
// type: object
142
150
// properties:
@@ -166,6 +174,12 @@ func testSchema() *schema.Structural {
166
174
// format: int64
167
175
// default: 1
168
176
// enum: [1,2,3]
177
+ // intOrString:
178
+ // x-kubernetes-int-or-string: true
179
+ // anyOf:
180
+ // - type: "integer"
181
+ // - type: "string"
182
+ // maxLength: 20
169
183
ts := & schema.Structural {
170
184
Generic : schema.Generic {
171
185
Type : "object" ,
@@ -175,6 +189,9 @@ func testSchema() *schema.Structural {
175
189
Generic : schema.Generic {
176
190
Type : "string" ,
177
191
},
192
+ ValueValidation : & schema.ValueValidation {
193
+ MaxLength : maxPtr (256 ),
194
+ },
178
195
},
179
196
"value" : {
180
197
Generic : schema.Generic {
@@ -245,6 +262,26 @@ func testSchema() *schema.Structural {
245
262
},
246
263
},
247
264
},
265
+ "intOrString" : {
266
+ Extensions : schema.Extensions {
267
+ XIntOrString : true ,
268
+ },
269
+ ValueValidation : & schema.ValueValidation {
270
+ MaxLength : maxPtr (20 ),
271
+ AnyOf : []schema.NestedValueValidation {
272
+ {
273
+ ForbiddenGenerics : schema.Generic {
274
+ Type : "integer" ,
275
+ },
276
+ },
277
+ {
278
+ ForbiddenGenerics : schema.Generic {
279
+ Type : "string" ,
280
+ },
281
+ },
282
+ },
283
+ },
284
+ },
248
285
},
249
286
}
250
287
return ts
0 commit comments