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

all: Remove remaining Block-based MaxItems and MinItems functionality #577

Merged
merged 3 commits into from Dec 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 0 additions & 16 deletions datasource/schema/list_nested_block.go
Expand Up @@ -158,22 +158,6 @@ func (b ListNestedBlock) GetMarkdownDescription() string {
return b.MarkdownDescription
}

// GetMaxItems always returns 0.
//
// Deprecated: This method will be removed in the future. Use validators
// instead.
func (b ListNestedBlock) GetMaxItems() int64 {
return 0
}

// GetMinItems always returns 0.
//
// Deprecated: This method will be removed in the future. Use validators
// instead.
func (b ListNestedBlock) GetMinItems() int64 {
return 0
}

// GetNestedObject returns the NestedObject field value.
func (b ListNestedBlock) GetNestedObject() fwschema.NestedBlockObject {
return b.NestedObject
Expand Down
68 changes: 0 additions & 68 deletions datasource/schema/list_nested_block_test.go
Expand Up @@ -297,74 +297,6 @@ func TestListNestedBlockGetMarkdownDescription(t *testing.T) {
}
}

func TestListNestedBlockGetMaxItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.ListNestedBlock
expected int64
}{
"0": {
block: schema.ListNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMaxItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestListNestedBlockGetMinItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.ListNestedBlock
expected int64
}{
"0": {
block: schema.ListNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMinItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestListNestedBlockGetNestedObject(t *testing.T) {
t.Parallel()

Expand Down
16 changes: 0 additions & 16 deletions datasource/schema/set_nested_block.go
Expand Up @@ -158,22 +158,6 @@ func (b SetNestedBlock) GetMarkdownDescription() string {
return b.MarkdownDescription
}

// GetMaxItems always returns 0.
//
// Deprecated: This method will be removed in the future. Use validators
// instead.
func (b SetNestedBlock) GetMaxItems() int64 {
return 0
}

// GetMinItems always returns 0.
//
// Deprecated: This method will be removed in the future. Use validators
// instead.
func (b SetNestedBlock) GetMinItems() int64 {
return 0
}

// GetNestedObject returns the NestedObject field value.
func (b SetNestedBlock) GetNestedObject() fwschema.NestedBlockObject {
return b.NestedObject
Expand Down
68 changes: 0 additions & 68 deletions datasource/schema/set_nested_block_test.go
Expand Up @@ -297,74 +297,6 @@ func TestSetNestedBlockGetMarkdownDescription(t *testing.T) {
}
}

func TestSetNestedBlockGetMaxItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.SetNestedBlock
expected int64
}{
"0": {
block: schema.SetNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMaxItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestSetNestedBlockGetMinItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.SetNestedBlock
expected int64
}{
"0": {
block: schema.SetNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMinItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestSetNestedBlockGetNestedObject(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 0 additions & 14 deletions datasource/schema/single_nested_block.go
Expand Up @@ -167,20 +167,6 @@ func (b SingleNestedBlock) GetMarkdownDescription() string {
return b.MarkdownDescription
}

// GetMaxItems always returns 0.
//
// Deprecated: This method will be removed in the future.
func (b SingleNestedBlock) GetMaxItems() int64 {
return 0
}

// GetMinItems always returns 0.
//
// Deprecated: This method will be removed in the future.
func (b SingleNestedBlock) GetMinItems() int64 {
return 0
}

// GetNestedObject returns a generated NestedBlockObject from the
// Attributes, CustomType, and Validators field values.
func (b SingleNestedBlock) GetNestedObject() fwschema.NestedBlockObject {
Expand Down
64 changes: 0 additions & 64 deletions datasource/schema/single_nested_block_test.go
Expand Up @@ -297,70 +297,6 @@ func TestSingleNestedBlockGetMarkdownDescription(t *testing.T) {
}
}

func TestSingleNestedBlockGetMaxItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.SingleNestedBlock
expected int64
}{
"0": {
block: schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMaxItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestSingleNestedBlockGetMinItems(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
block schema.SingleNestedBlock
expected int64
}{
"0": {
block: schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"testattr": schema.StringAttribute{},
},
},
expected: 0,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.block.GetMinItems()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestSingleNestedBlockGetNestedObject(t *testing.T) {
t.Parallel()

Expand Down
25 changes: 7 additions & 18 deletions internal/fwschema/block.go
Expand Up @@ -13,6 +13,13 @@ import (
// Refer to the internal/fwschema/fwxschema package for optional interfaces
// that define framework-specific functionality, such a plan modification and
// validation.
//
// Note that MaxItems and MinItems support, while defined in the Terraform
// protocol, is intentially not present. Terraform can only perform limited
// static analysis of blocks and errors generated occur before the provider
// is called for configuration validation, which means that practitioners do
// not get all configuration errors at the same time. Provider developers can
// implement validators to achieve the same validation functionality.
type Block interface {
// Implementations should include the tftypes.AttributePathStepper
// interface methods for proper path and data handling.
Expand All @@ -37,16 +44,6 @@ type Block interface {
// name.
GetMarkdownDescription() string

// GetMaxItems should return the max items of a block. This is named
// differently than MaxItems to prevent a conflict with the tfsdk.Block
// field name.
GetMaxItems() int64

// GetMinItems should return the min items of a block. This is named
// differently than MinItems to prevent a conflict with the tfsdk.Block
// field name.
GetMinItems() int64

// GetNestedObject should return the object underneath the block.
// For single nesting mode, the NestedBlockObject can be generated from
// the Block.
Expand Down Expand Up @@ -81,13 +78,5 @@ func BlocksEqual(a, b Block) bool {
return false
}

if a.GetMaxItems() != b.GetMaxItems() {
return false
}

if a.GetMinItems() != b.GetMinItems() {
return false
}

return true
}