Skip to content

Commit

Permalink
Merge pull request #39353 from hashicorp/td/add-more-tests
Browse files Browse the repository at this point in the history
td/Add tests to slot_type and fixes
  • Loading branch information
nam054 authored Sep 17, 2024
2 parents 18b873b + d1c0784 commit 1d128ad
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changelog/39353.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
``release-note:breaking-change
resource/aws_lexv2models_slot_type: Within the `composite_slot_type_setting` block, the `subslots` argument has been renamed `sub_slots`
```

```release-note:note
resource/aws_lexv2models_slot_type: Within the `composite_slot_type_setting` block, the `subslots` argument has been renamed `sub_slots`. See the [linked pull request](https://github.com/hashicorp/terraform-provider-aws/pull/39353) for additional justification on this change. The previous misnaming effectively made this argument unusable, therefore a breaking change in a minor version was deemed acceptable.
```
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,
},
},
},
"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))
}

0 comments on commit 1d128ad

Please sign in to comment.