Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add test for required properties in clusterclass variables #9113

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
killianmuldoon marked this conversation as resolved.
Show resolved Hide resolved
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