@@ -929,7 +929,6 @@ func Test_DefaultClusterVariable(t *testing.T) {
929
929
Schema : clusterv1.VariableSchema {
930
930
OpenAPIV3Schema : clusterv1.JSONSchemaProps {
931
931
Type : "object" ,
932
-
933
932
Properties : map [string ]clusterv1.JSONSchemaProps {
934
933
"enabled" : {
935
934
Type : "boolean" ,
@@ -949,6 +948,76 @@ func Test_DefaultClusterVariable(t *testing.T) {
949
948
createVariable : true ,
950
949
want : nil ,
951
950
},
951
+ {
952
+ name : "Default new object variable if there is a top-level default" ,
953
+ clusterClassVariable : & statusVariableDefinition {
954
+ Name : "httpProxy" ,
955
+ ClusterClassStatusVariableDefinition : & clusterv1.ClusterClassStatusVariableDefinition {
956
+ Required : true ,
957
+ Schema : clusterv1.VariableSchema {
958
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
959
+ Type : "object" ,
960
+ Default : & apiextensionsv1.JSON {Raw : []byte (`{"url":"test-url"}` )},
961
+ Properties : map [string ]clusterv1.JSONSchemaProps {
962
+ "enabled" : {
963
+ Type : "boolean" ,
964
+ Default : & apiextensionsv1.JSON {Raw : []byte (`false` )},
965
+ },
966
+ "url" : {
967
+ Type : "string" ,
968
+ },
969
+ "noProxy" : {
970
+ Type : "string" ,
971
+ },
972
+ },
973
+ },
974
+ },
975
+ },
976
+ },
977
+ createVariable : true ,
978
+ want : & clusterv1.ClusterVariable {
979
+ Name : "httpProxy" ,
980
+ Value : apiextensionsv1.JSON {
981
+ // Defaulting first adds the top-level object and then the enabled field.
982
+ Raw : []byte (`{"enabled":false,"url":"test-url"}` ),
983
+ },
984
+ },
985
+ },
986
+ {
987
+ name : "Default new object variable if there is a top-level default (which is an empty object)" ,
988
+ clusterClassVariable : & statusVariableDefinition {
989
+ Name : "httpProxy" ,
990
+ ClusterClassStatusVariableDefinition : & clusterv1.ClusterClassStatusVariableDefinition {
991
+ Required : true ,
992
+ Schema : clusterv1.VariableSchema {
993
+ OpenAPIV3Schema : clusterv1.JSONSchemaProps {
994
+ Type : "object" ,
995
+ Default : & apiextensionsv1.JSON {Raw : []byte (`{}` )},
996
+ Properties : map [string ]clusterv1.JSONSchemaProps {
997
+ "enabled" : {
998
+ Type : "boolean" ,
999
+ Default : & apiextensionsv1.JSON {Raw : []byte (`false` )},
1000
+ },
1001
+ "url" : {
1002
+ Type : "string" ,
1003
+ },
1004
+ "noProxy" : {
1005
+ Type : "string" ,
1006
+ },
1007
+ },
1008
+ },
1009
+ },
1010
+ },
1011
+ },
1012
+ createVariable : true ,
1013
+ want : & clusterv1.ClusterVariable {
1014
+ Name : "httpProxy" ,
1015
+ Value : apiextensionsv1.JSON {
1016
+ // Defaulting first adds the top-level empty object and then the enabled field.
1017
+ Raw : []byte (`{"enabled":false}` ),
1018
+ },
1019
+ },
1020
+ },
952
1021
{
953
1022
name : "Don't default existing object variable" ,
954
1023
clusterClassVariable : & statusVariableDefinition {
0 commit comments