Skip to content

Commit e51bdfb

Browse files
committed
Add additional test cases for nested variable defaulting
Signed-off-by: Stefan Büringer [email protected]
1 parent 93d6e79 commit e51bdfb

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

internal/topology/variables/cluster_variable_defaulting_test.go

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ func Test_DefaultClusterVariable(t *testing.T) {
929929
Schema: clusterv1.VariableSchema{
930930
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
931931
Type: "object",
932-
933932
Properties: map[string]clusterv1.JSONSchemaProps{
934933
"enabled": {
935934
Type: "boolean",
@@ -949,6 +948,76 @@ func Test_DefaultClusterVariable(t *testing.T) {
949948
createVariable: true,
950949
want: nil,
951950
},
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+
},
9521021
{
9531022
name: "Don't default existing object variable",
9541023
clusterClassVariable: &statusVariableDefinition{

0 commit comments

Comments
 (0)