Skip to content

Commit

Permalink
Using testschema throughout tests for attribute and block plan modifi…
Browse files Browse the repository at this point in the history
…er (#821)
  • Loading branch information
bendbennett committed Aug 16, 2023
1 parent 3f4d956 commit 0f46f8d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 54 deletions.
127 changes: 73 additions & 54 deletions internal/fwserver/attribute_plan_modification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,23 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-list-nested-custom-nested-object": {
attribute: schema.ListNestedAttribute{
NestedObject: schema.NestedAttributeObject{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"nested_attr": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeList,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.ListValueMust(
Expand Down Expand Up @@ -241,8 +242,8 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-list-nested-nested-custom-nested-object": {
attribute: schema.ListNestedAttribute{
NestedObject: schema.NestedAttributeObject{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.ListNestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
Expand All @@ -258,27 +259,29 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
},
Attributes: map[string]schema.Attribute{
"nested_list_nested_attribute": schema.ListNestedAttribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"nested_list_nested_attribute": testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"nested_attr": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeList,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeList,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.ListValueMust(
Expand Down Expand Up @@ -1033,15 +1036,16 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-set-nested-custom-nested-object": {
attribute: schema.SetNestedAttribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeSet,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.SetValueMust(
Expand Down Expand Up @@ -1134,8 +1138,8 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-set-nested-nested-custom-nested-object": {
attribute: schema.SetNestedAttribute{
NestedObject: schema.NestedAttributeObject{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.SetNestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
Expand All @@ -1151,27 +1155,29 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
},
Attributes: map[string]schema.Attribute{
"nested_set_nested_attribute": schema.SetNestedAttribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"nested_set_nested_attribute": testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"nested_attr": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeSet,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeSet,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.SetValueMust(
Expand Down Expand Up @@ -2067,22 +2073,23 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-map-nested-custom-nested-object": {
attribute: schema.MapNestedAttribute{
NestedObject: schema.NestedAttributeObject{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"nested_attr": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeMap,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.MapValueMust(
Expand Down Expand Up @@ -2175,8 +2182,8 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-map-nested-nested-custom-nested-object": {
attribute: schema.MapNestedAttribute{
NestedObject: schema.NestedAttributeObject{
attribute: testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.MapNestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
Expand All @@ -2192,27 +2199,29 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
},
Attributes: map[string]schema.Attribute{
"nested_map_nested_attribute": schema.MapNestedAttribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"nested_map_nested_attribute": testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"nested_attr": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"nested_attr": schema.StringAttribute{
Attributes: map[string]fwschema.Attribute{
"nested_attr": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeMap,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeMap,
},
req: ModifyAttributePlanRequest{
AttributeConfig: types.MapValueMust(
Expand Down Expand Up @@ -2697,20 +2706,23 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-single-nested-custom": {
attribute: schema.SingleNestedAttribute{
attribute: testschema.NestedAttribute{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
"testing": types.StringType,
},
},
},
Attributes: map[string]schema.Attribute{
"testing": schema.StringAttribute{
Required: true,
NestedObject: testschema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"testing": testschema.Attribute{
Required: true,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeSingle,
},
req: ModifyAttributePlanRequest{
AttributeConfig: testschema.NestedObjectCustomValue{
Expand Down Expand Up @@ -2759,7 +2771,7 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
"attribute-single-nested-nested-custom-nested-object": {
attribute: schema.SingleNestedAttribute{
attribute: testschema.NestedAttribute{
CustomType: testschema.NestedObjectCustomType{
ObjectType: basetypes.ObjectType{
AttrTypes: map[string]attr.Type{
Expand All @@ -2773,16 +2785,23 @@ func TestAttributeModifyPlan(t *testing.T) {
},
},
},
Attributes: map[string]schema.Attribute{
"nested_single_nested_attribute": schema.SingleNestedAttribute{
Attributes: map[string]schema.Attribute{
"testing": schema.StringAttribute{
Required: true,
NestedObject: testschema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"nested_single_nested_attribute": testschema.NestedAttribute{
NestedObject: testschema.NestedAttributeObject{
Attributes: map[string]fwschema.Attribute{
"testing": testschema.Attribute{
Required: true,
},
},
},
Required: true,
NestingMode: fwschema.NestingModeSingle,
},
},
},
Required: true,
Required: true,
NestingMode: fwschema.NestingModeSingle,
},
req: ModifyAttributePlanRequest{
AttributeConfig: testschema.NestedObjectCustomValue{
Expand Down
2 changes: 2 additions & 0 deletions internal/testing/testschema/nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

var _ fwschema.NestedAttribute = NestedAttribute{}

type NestedAttribute struct {
Computed bool
CustomType basetypes.ObjectTypable
DeprecationMessage string
Description string
MarkdownDescription string
Expand Down

0 comments on commit 0f46f8d

Please sign in to comment.