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

td/Add tests to slot_type and fixes #39353

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 3 additions & 15 deletions internal/service/lexv2models/slot_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,22 @@ func (r *resourceSlotType) Schema(ctx context.Context, req resource.SchemaReques
},
Blocks: map[string]schema.Block{
"composite_slot_type_setting": schema.ListNestedBlock{
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
CustomType: fwtypes.NewListNestedObjectTypeOf[CompositeSlotTypeSetting](ctx),
NestedObject: schema.NestedBlockObject{
Blocks: map[string]schema.Block{
"subslots": subSlotTypeCompositionLNB,
"sub_slots": subSlotTypeCompositionLNB,
nam054 marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
"external_source_setting": schema.ListNestedBlock{
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
CustomType: fwtypes.NewListNestedObjectTypeOf[ExternalSourceSetting](ctx),
NestedObject: schema.NestedBlockObject{
Blocks: map[string]schema.Block{
"grammar_slot_type_setting": schema.ListNestedBlock{
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
CustomType: fwtypes.NewListNestedObjectTypeOf[GrammarSlotTypeSetting](ctx),
NestedObject: schema.NestedBlockObject{
Blocks: map[string]schema.Block{
names.AttrSource: schema.ListNestedBlock{
Validators: []validator.List{
listvalidator.SizeAtMost(1),
},
CustomType: fwtypes.NewListNestedObjectTypeOf[Source](ctx),
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -456,8 +444,8 @@ type resourceSlotTypeData struct {
}

type SubSlotTypeComposition struct {
Name types.String `tfsdk:"name"`
SubSlotID types.String `tfsdk:"sub_slot_id"`
Name types.String `tfsdk:"name"`
SlotTypeID types.String `tfsdk:"slot_type_id"`
}

type CompositeSlotTypeSetting struct {
Expand Down
56 changes: 56 additions & 0 deletions internal/service/lexv2models/slot_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,38 @@ func TestAccLexV2ModelsSlotType_valueSelectionSetting(t *testing.T) {
})
}

func TestAccLexV2ModelsSlotType_compositeSlotTypeSetting(t *testing.T) {
ctx := acctest.Context(t)

var slottype lexmodelsv2.DescribeSlotTypeOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_lexv2models_slot_type.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.LexV2ModelsEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.LexV2ModelsServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckSlotTypeDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccSlotTypeConfig_compositeSlotTypeSetting(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckSlotTypeExists(ctx, resourceName, &slottype),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "composite_slot_type_setting.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "composite_slot_type_setting.0.sub_slots.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "composite_slot_type_setting.0.sub_slots.0.name", "testname"),
resource.TestCheckResourceAttr(resourceName, "composite_slot_type_setting.0.sub_slots.0.slot_type_id", "AMAZON.Date"),
),
},
},
})
}

func testAccCheckSlotTypeDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).LexV2ModelsClient(ctx)
Expand Down Expand Up @@ -334,3 +366,27 @@ resource "aws_lexv2models_slot_type" "test" {
}
`, rName, audioRecognitionStrategy))
}

func testAccSlotTypeConfig_compositeSlotTypeSetting(rName string) string {
return acctest.ConfigCompose(
testAccSlotTypeConfig_base(rName, 60, true),
fmt.Sprintf(`
resource "aws_lexv2models_slot_type" "test" {
bot_id = aws_lexv2models_bot.test.id
bot_version = aws_lexv2models_bot_locale.test.bot_version
name = %[1]q
locale_id = aws_lexv2models_bot_locale.test.locale_id

value_selection_setting {
resolution_strategy = "Concatenation"
}

composite_slot_type_setting {
sub_slots {
name = "testname"
slot_type_id = "AMAZON.Date"
}
}
}
`, rName))
}
Loading