@@ -497,7 +497,8 @@ func Test_ValidateClusterClassVariable(t *testing.T) {
497
497
{
498
498
name : "pass on variable with required set true with a default defined" ,
499
499
clusterClassVariable : & clusterv1.ClusterClassVariable {
500
- Name : "var" ,
500
+ Name : "var" ,
501
+ Required : true ,
501
502
Schema : clusterv1.VariableSchema {
502
503
OpenAPIV3Schema : clusterv1.JSONSchemaProps {
503
504
Type : "string" ,
@@ -631,6 +632,68 @@ func Test_ValidateClusterClassVariable(t *testing.T) {
631
632
},
632
633
},
633
634
},
635
+ {
636
+ name : "fail if field is required below properties and sets a default that misses the field" ,
637
+ clusterClassVariable : & clusterv1.ClusterClassVariable {
638
+ Name : "var" ,
639
+ Schema : clusterv1.VariableSchema {
640
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
641
+ Type : "object" ,
642
+ Properties : map [string ]clusterv1.JSONSchemaProps {
643
+ "spec" : {
644
+ Type : "object" ,
645
+ Required : []string {"replicas" },
646
+ Default : & apiextensionsv1.JSON {
647
+ // replicas missing results in failure
648
+ Raw : []byte (`{"value": 100}` ),
649
+ },
650
+ Properties : map [string ]clusterv1.JSONSchemaProps {
651
+ "replicas" : {
652
+ Type : "integer" ,
653
+ Default : & apiextensionsv1.JSON {Raw : []byte (`100` )},
654
+ Minimum : pointer .Int64 (1 ),
655
+ },
656
+ "value" : {
657
+ Type : "integer" ,
658
+ Default : & apiextensionsv1.JSON {Raw : []byte (`100` )},
659
+ Minimum : pointer .Int64 (1 ),
660
+ },
661
+ },
662
+ },
663
+ },
664
+ },
665
+ },
666
+ },
667
+ wantErr : true ,
668
+ },
669
+ {
670
+ name : "pass if field is required below properties and sets a default" ,
671
+ clusterClassVariable : & clusterv1.ClusterClassVariable {
672
+ Name : "var" ,
673
+ Schema : clusterv1.VariableSchema {
674
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
675
+ Type : "object" ,
676
+ Properties : map [string ]clusterv1.JSONSchemaProps {
677
+ "spec" : {
678
+ Type : "object" ,
679
+ Required : []string {"replicas" },
680
+ Default : & apiextensionsv1.JSON {
681
+ // replicas is set here so the `required` property is met.
682
+ Raw : []byte (`{"replicas": 100}` ),
683
+ },
684
+ Properties : map [string ]clusterv1.JSONSchemaProps {
685
+ "replicas" : {
686
+ Type : "integer" ,
687
+ Default : & apiextensionsv1.JSON {Raw : []byte (`100` )},
688
+ Minimum : pointer .Int64 (1 ),
689
+ },
690
+ },
691
+ },
692
+ },
693
+ },
694
+ },
695
+ },
696
+ },
634
697
635
698
{
636
699
name : "pass on variable with an example that is valid by the given schema" ,
0 commit comments