Skip to content

Commit

Permalink
Merge pull request #9113 from killianmuldoon/pr-required-properties
Browse files Browse the repository at this point in the history
🌱 Add test for required properties in clusterclass variables
  • Loading branch information
k8s-ci-robot committed Aug 18, 2023
2 parents c79c7d3 + 1b7b56e commit a4cd9d1
Showing 1 changed file with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ func Test_ValidateClusterClassVariable(t *testing.T) {
{
name: "pass on variable with required set true with a default defined",
clusterClassVariable: &clusterv1.ClusterClassVariable{
Name: "var",
Name: "var",
Required: true,
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "string",
Expand Down Expand Up @@ -631,6 +632,68 @@ func Test_ValidateClusterClassVariable(t *testing.T) {
},
},
},
{
name: "fail if field is required below properties and sets a default that misses the field",
clusterClassVariable: &clusterv1.ClusterClassVariable{
Name: "var",
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"spec": {
Type: "object",
Required: []string{"replicas"},
Default: &apiextensionsv1.JSON{
// replicas missing results in failure
Raw: []byte(`{"value": 100}`),
},
Properties: map[string]clusterv1.JSONSchemaProps{
"replicas": {
Type: "integer",
Default: &apiextensionsv1.JSON{Raw: []byte(`100`)},
Minimum: pointer.Int64(1),
},
"value": {
Type: "integer",
Default: &apiextensionsv1.JSON{Raw: []byte(`100`)},
Minimum: pointer.Int64(1),
},
},
},
},
},
},
},
wantErr: true,
},
{
name: "pass if field is required below properties and sets a default",
clusterClassVariable: &clusterv1.ClusterClassVariable{
Name: "var",
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"spec": {
Type: "object",
Required: []string{"replicas"},
Default: &apiextensionsv1.JSON{
// replicas is set here so the `required` property is met.
Raw: []byte(`{"replicas": 100}`),
},
Properties: map[string]clusterv1.JSONSchemaProps{
"replicas": {
Type: "integer",
Default: &apiextensionsv1.JSON{Raw: []byte(`100`)},
Minimum: pointer.Int64(1),
},
},
},
},
},
},
},
},

{
name: "pass on variable with an example that is valid by the given schema",
Expand Down

0 comments on commit a4cd9d1

Please sign in to comment.