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

CDPCP-11322 - DL recipes should not be an attributeless SetNestedAttribute - GCP #83

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions resources/datalake/common_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ var generalAttributes = map[string]schema.Attribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"instance_group_name": schema.StringAttribute{
Required: true,
MarkdownDescription: "The name of the designated instance group.",
Required: true,
},
"recipe_names": schema.SetNestedAttribute{
Required: true,
"recipe_names": schema.SetAttribute{
MarkdownDescription: "The set of recipe names that are going to be applied on the given instance group.",
ElementType: types.StringType,
Required: true,
},
},
},
Expand Down
234 changes: 130 additions & 104 deletions resources/datalake/common_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package datalake

import (
"reflect"
"testing"

"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand All @@ -21,112 +22,132 @@ type TestCaseStructure struct {
field string
computed bool
shouldBeRequired bool
attributeType schema.Attribute
}

var commonElementCaseSet = []TestCaseStructure{
{
name: "'id' field must exist",
field: "id",
computed: true,
shouldBeRequired: false,
},
{
name: "'polling_options' should exist",
field: "polling_options",
computed: false,
shouldBeRequired: false,
},
{
name: "'creation_date' should exist",
field: "creation_date",
computed: true,
shouldBeRequired: false,
},
{
name: "'crn' should exist",
field: "crn",
computed: true,
shouldBeRequired: false,
},
{
name: "'datalake_name' must exist",
field: "datalake_name",
computed: false,
shouldBeRequired: true,
},
{
name: "'enable_ranger_raz' should exist",
field: "enable_ranger_raz",
computed: true,
shouldBeRequired: false,
},
{
name: "'environment_crn' should exist",
field: "environment_crn",
computed: true,
shouldBeRequired: false,
},
{
name: "'environment_name' must exist",
field: "environment_name",
computed: false,
shouldBeRequired: true,
},
{
name: "'image' should exist",
field: "image",
computed: false,
shouldBeRequired: false,
},
{
name: "'java_version' should exist",
field: "java_version",
computed: false,
shouldBeRequired: false,
},
{
name: "'recipes' should exist",
field: "recipes",
computed: false,
shouldBeRequired: false,
},
{
name: "'runtime' should exist",
field: "runtime",
computed: false,
shouldBeRequired: false,
},
{
name: "'scale' should exist",
field: "scale",
computed: true,
shouldBeRequired: false,
},
{
name: "'status' should exist",
field: "status",
computed: true,
shouldBeRequired: false,
},
{
name: "'status_reason' should exist",
field: "status_reason",
computed: true,
shouldBeRequired: false,
},
{
name: "'multi_az' should exist",
field: "multi_az",
computed: true,
shouldBeRequired: false,
},
{
name: "'tags' should exist",
field: "tags",
computed: false,
shouldBeRequired: false,
},
}
var (
commonElementCaseSet = []TestCaseStructure{
{
name: "'id' field must exist",
field: "id",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'polling_options' should exist",
field: "polling_options",
computed: false,
shouldBeRequired: false,
attributeType: schema.SingleNestedAttribute{},
},
{
name: "'creation_date' should exist",
field: "creation_date",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'crn' should exist",
field: "crn",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'datalake_name' must exist",
field: "datalake_name",
computed: false,
shouldBeRequired: true,
attributeType: schema.StringAttribute{},
},
{
name: "'enable_ranger_raz' should exist",
field: "enable_ranger_raz",
computed: true,
shouldBeRequired: false,
attributeType: schema.BoolAttribute{},
},
{
name: "'environment_crn' should exist",
field: "environment_crn",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'environment_name' must exist",
field: "environment_name",
computed: false,
shouldBeRequired: true,
attributeType: schema.StringAttribute{},
},
{
name: "'image' should exist",
field: "image",
computed: false,
shouldBeRequired: false,
attributeType: schema.SingleNestedAttribute{},
},
{
name: "'java_version' should exist",
field: "java_version",
computed: false,
shouldBeRequired: false,
attributeType: schema.Int64Attribute{},
},
{
name: "'recipes' should exist",
field: "recipes",
computed: false,
shouldBeRequired: false,
attributeType: schema.SetNestedAttribute{},
},
{
name: "'runtime' should exist",
field: "runtime",
computed: false,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'scale' should exist",
field: "scale",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'status' should exist",
field: "status",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'status_reason' should exist",
field: "status_reason",
computed: true,
shouldBeRequired: false,
attributeType: schema.StringAttribute{},
},
{
name: "'multi_az' should exist",
field: "multi_az",
computed: true,
shouldBeRequired: false,
attributeType: schema.BoolAttribute{},
},
{
name: "'tags' should exist",
field: "tags",
computed: false,
shouldBeRequired: false,
attributeType: schema.MapAttribute{},
},
}
)

func TestRootElements(t *testing.T) {
SchemaContainsCommonElements(t, generalAttributes)
Expand All @@ -145,6 +166,11 @@ func SchemaContainsCommonElements(t *testing.T, providerSpecificSchema map[strin
if providerSpecificSchema[test.field].IsComputed() != test.computed {
t.Errorf("The '%s' filed's >computed< property should be: %t", test.field, test.computed)
}
var currentType = reflect.TypeOf(providerSpecificSchema[test.field])
var expectedType = reflect.TypeOf(test.attributeType)
if currentType != expectedType {
t.Errorf("The '%s' field's type should be: %t, instead of %t", test.field, expectedType, currentType)
}
})
}
}
2 changes: 2 additions & 0 deletions resources/datalake/schema_gcp_datalake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ func TestGcpSpecificElements(t *testing.T) {
field: "custom_instance_groups",
computed: false,
shouldBeRequired: false,
attributeType: schema.SetNestedAttribute{},
},
{
name: "cloud_provider_configuration should exist",
field: "cloud_provider_configuration",
computed: false,
shouldBeRequired: true,
attributeType: schema.SingleNestedAttribute{},
},
}

Expand Down
Loading