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

internal/framework/flex: support set of enum expansion #36789

Merged
merged 1 commit into from
Apr 9, 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
8 changes: 7 additions & 1 deletion internal/framework/flex/auto_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,13 @@ func (expander autoExpander) setOfString(ctx context.Context, vFrom basetypes.Se
return diags
}

vTo.Set(reflect.ValueOf(to))
// Copy elements individually to enable expansion of lists of
// custom string types (AWS enums)
vals := reflect.MakeSlice(vTo.Type(), len(to), len(to))
for i := 0; i < len(to); i++ {
vals.Index(i).SetString(to[i])
}
vTo.Set(vals)
return diags

case reflect.Ptr:
Expand Down
74 changes: 74 additions & 0 deletions internal/framework/flex/auto_expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,80 @@ func TestExpandStringEnum(t *testing.T) {
runAutoExpandTestCases(ctx, t, testCases)
}

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

type testEnum string
var testEnumFoo testEnum = "foo"
var testEnumBar testEnum = "bar"

var testEnums []testEnum
testEnumsWant := []testEnum{testEnumFoo, testEnumBar}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "valid value",
Source: types.ListValueMust(types.StringType, []attr.Value{
types.StringValue(string(testEnumFoo)),
types.StringValue(string(testEnumBar)),
}),
Target: &testEnums,
WantTarget: &testEnumsWant,
},
{
TestName: "empty value",
Source: types.ListValueMust(types.StringType, []attr.Value{}),
Target: &testEnums,
WantTarget: &testEnums,
},
{
TestName: "null value",
Source: types.ListNull(types.StringType),
Target: &testEnums,
WantTarget: &testEnums,
},
}
runAutoExpandTestCases(ctx, t, testCases)
}

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

type testEnum string
var testEnumFoo testEnum = "foo"
var testEnumBar testEnum = "bar"

var testEnums []testEnum
testEnumsWant := []testEnum{testEnumFoo, testEnumBar}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "valid value",
Source: types.SetValueMust(types.StringType, []attr.Value{
types.StringValue(string(testEnumFoo)),
types.StringValue(string(testEnumBar)),
}),
Target: &testEnums,
WantTarget: &testEnumsWant,
},
{
TestName: "empty value",
Source: types.SetValueMust(types.StringType, []attr.Value{}),
Target: &testEnums,
WantTarget: &testEnums,
},
{
TestName: "null value",
Source: types.SetNull(types.StringType),
Target: &testEnums,
WantTarget: &testEnums,
},
}
runAutoExpandTestCases(ctx, t, testCases)
}

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

Expand Down
Loading