Skip to content

Commit

Permalink
internal/fwtype: Add custom type test cases for ContainsMissingUnderl…
Browse files Browse the repository at this point in the history
…yingType
  • Loading branch information
bflad committed Apr 24, 2024
1 parent 868c0a0 commit 8de2744
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions internal/fwtype/missing_underlying_type_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwtype"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand All @@ -23,6 +24,7 @@ func TestContainsMissingUnderlyingType(t *testing.T) {
attrTyp: nil,
expected: true,
},
// custom type test cases are below all of the base type test cases
"bool": {
attrTyp: types.BoolType,
expected: false,
Expand Down Expand Up @@ -1594,6 +1596,61 @@ func TestContainsMissingUnderlyingType(t *testing.T) {
},
expected: true,
},
"custom-bool": {
attrTyp: testtypes.BoolType{},
expected: false,
},
"custom-dynamic": {
attrTyp: testtypes.DynamicType{},
expected: false,
},
"custom-float64": {
attrTyp: testtypes.Float64Type{},
expected: false,
},
"custom-int64": {
attrTyp: testtypes.Int64Type{},
expected: false,
},
"custom-list-nil": {
attrTyp: testtypes.ListType{},
// While testtypes.ListType embeds basetypes.ListType and this test
// case does not specify an ElemType value, the function logic is
// coded to only handle basetypes implementations due to the
// unexported missingType that would be returned from the
// ElementType() method which would be used for custom types.
expected: false,
},
"custom-map-nil": {
attrTyp: testtypes.MapType{},
// While testtypes.MapType embeds basetypes.MapType and this test
// case does not specify an ElemType value, the function logic is
// coded to only handle basetypes implementations due to the
// unexported missingType that would be returned from the
// ElementType() method which would be used for custom types.
expected: false,
},
"custom-object-nil": {
attrTyp: testtypes.ObjectType{},
expected: false, // expected as objects can be empty
},
"custom-number": {
attrTyp: testtypes.NumberType{},
expected: false,
},
"custom-set-nil": {
attrTyp: testtypes.SetType{},
// While testtypes.SetType embeds basetypes.SetType and this test
// case does not specify an ElemType value, the function logic is
// coded to only handle basetypes implementations due to the
// unexported missingType that would be returned from the
// ElementType() method which would be used for custom types.
expected: false,
},
"custom-string": {
attrTyp: testtypes.StringType{},
expected: false,
},
}
for name, testCase := range testCases {
name, testCase := name, testCase
Expand Down

0 comments on commit 8de2744

Please sign in to comment.