Skip to content

Commit

Permalink
Merge pull request #9728 from sbueringer/pr-add-default-unit-test
Browse files Browse the repository at this point in the history
🌱 Add additional test cases for nested variable defaulting
  • Loading branch information
k8s-ci-robot authored Nov 16, 2023
2 parents 672e2a1 + e51bdfb commit 2144ee8
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion internal/topology/variables/cluster_variable_defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@ func Test_DefaultClusterVariable(t *testing.T) {
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",

Properties: map[string]clusterv1.JSONSchemaProps{
"enabled": {
Type: "boolean",
Expand All @@ -949,6 +948,76 @@ func Test_DefaultClusterVariable(t *testing.T) {
createVariable: true,
want: nil,
},
{
name: "Default new object variable if there is a top-level default",
clusterClassVariable: &statusVariableDefinition{
Name: "httpProxy",
ClusterClassStatusVariableDefinition: &clusterv1.ClusterClassStatusVariableDefinition{
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Default: &apiextensionsv1.JSON{Raw: []byte(`{"url":"test-url"}`)},
Properties: map[string]clusterv1.JSONSchemaProps{
"enabled": {
Type: "boolean",
Default: &apiextensionsv1.JSON{Raw: []byte(`false`)},
},
"url": {
Type: "string",
},
"noProxy": {
Type: "string",
},
},
},
},
},
},
createVariable: true,
want: &clusterv1.ClusterVariable{
Name: "httpProxy",
Value: apiextensionsv1.JSON{
// Defaulting first adds the top-level object and then the enabled field.
Raw: []byte(`{"enabled":false,"url":"test-url"}`),
},
},
},
{
name: "Default new object variable if there is a top-level default (which is an empty object)",
clusterClassVariable: &statusVariableDefinition{
Name: "httpProxy",
ClusterClassStatusVariableDefinition: &clusterv1.ClusterClassStatusVariableDefinition{
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Default: &apiextensionsv1.JSON{Raw: []byte(`{}`)},
Properties: map[string]clusterv1.JSONSchemaProps{
"enabled": {
Type: "boolean",
Default: &apiextensionsv1.JSON{Raw: []byte(`false`)},
},
"url": {
Type: "string",
},
"noProxy": {
Type: "string",
},
},
},
},
},
},
createVariable: true,
want: &clusterv1.ClusterVariable{
Name: "httpProxy",
Value: apiextensionsv1.JSON{
// Defaulting first adds the top-level empty object and then the enabled field.
Raw: []byte(`{"enabled":false}`),
},
},
},
{
name: "Don't default existing object variable",
clusterClassVariable: &statusVariableDefinition{
Expand Down

0 comments on commit 2144ee8

Please sign in to comment.