Skip to content

Commit

Permalink
Add test for required properties in clusterclass variables
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
  • Loading branch information
killianmuldoon committed Aug 3, 2023
1 parent 1567f68 commit f87369b
Showing 1 changed file with 67 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,71 @@ func Test_ValidateClusterClassVariable(t *testing.T) {
},
},
},
{
name: "fail if field is required below properties and sets a default",
wantErr: true,
clusterClassVariable: &clusterv1.ClusterClassVariable{
Name: "var",
Schema: clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"spec": {
Type: "object",
Required: []string{"replicas"},
Example: &apiextensionsv1.JSON{
// replicas missing results in failure
Raw: []byte(`{"value": 100}`),
},
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),
},
},
},
},
},
},
},
},
{
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"},
Example: &apiextensionsv1.JSON{
// replicas is set here so the `required` property is met.
Raw: []byte(`{"replicas": 100}`),
},
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 f87369b

Please sign in to comment.