Skip to content

Commit

Permalink
Fixup acceptance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 2, 2024
1 parent 417e20f commit f16b146
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func testAccCheckAgentKnowledgeBaseAssociationExists(ctx context.Context, n stri
func testAccAgentKnowledgeBaseAssociationConfig_basic(rName, agentModel, embeddingModel, description, state string) string {
return acctest.ConfigCompose(
testAccAgentConfig_basic(rName, agentModel, description),
testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel),
testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel, ""),
fmt.Sprintf(`
resource "aws_bedrockagent_agent_knowledge_base_association" "test" {
agent_id = aws_bedrockagent_agent.test.id
Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrockagent/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func testAccCheckDataSourceExists(ctx context.Context, n string, v *types.DataSo
}

func testAccDataSourceConfig_base(rName, embeddingModel string) string {
return acctest.ConfigCompose(testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel), fmt.Sprintf(`
return acctest.ConfigCompose(testAccKnowledgeBaseConfig_basicRDS(rName, embeddingModel, ""), fmt.Sprintf(`
resource "aws_s3_bucket" "test" {
bucket = %[1]q
}
Expand Down
30 changes: 19 additions & 11 deletions internal/service/bedrockagent/knowledge_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package bedrockagent_test
import (
"context"
"fmt"
"strconv"
"testing"

"github.com/aws/aws-sdk-go-v2/service/bedrockagent/types"
Expand Down Expand Up @@ -33,8 +34,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) {

ctx := acctest.Context(t)
var knowledgebase types.KnowledgeBase
rName1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_bedrockagent_knowledge_base.test"
foundationModel := "amazon.titan-embed-text-v1"

Expand All @@ -53,7 +53,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) {
CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccKnowledgeBaseConfig_basicRDS(rName1, foundationModel),
Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, ""),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
Expand All @@ -65,7 +65,7 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName1),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"),
Expand All @@ -84,19 +84,19 @@ func testAccKnowledgeBase_basicRDS(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccKnowledgeBaseConfig_basicRDS(rName2, foundationModel),
Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, "test description"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
},
},
Check: resource.ComposeTestCheckFunc(
testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase),
resource.TestCheckNoResourceAttr(resourceName, names.AttrDescription),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, "test description"),
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.vector_knowledge_base_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "knowledge_base_configuration.0.type", "VECTOR"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName2),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "storage_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "storage_configuration.0.type", "RDS"),
Expand Down Expand Up @@ -142,7 +142,7 @@ func testAccKnowledgeBase_disappears(t *testing.T) {
CheckDestroy: testAccCheckKnowledgeBaseDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel),
Config: testAccKnowledgeBaseConfig_basicRDS(rName, foundationModel, ""),
Check: resource.ComposeTestCheckFunc(
testAccCheckKnowledgeBaseExists(ctx, resourceName, &knowledgebase),
acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfbedrockagent.ResourceKnowledgeBase, resourceName),
Expand Down Expand Up @@ -223,7 +223,7 @@ func testAccKnowledgeBase_tags(t *testing.T) {
Config: testAccKnowledgeBaseConfig_tags1(rName, foundationModel, acctest.CtKey2, acctest.CtValue2),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
},
},
ConfigStateChecks: []statecheck.StateCheck{
Expand Down Expand Up @@ -567,12 +567,20 @@ resource "null_resource" "db_setup" {
`, rName, model))
}

func testAccKnowledgeBaseConfig_basicRDS(rName, model string) string {
func testAccKnowledgeBaseConfig_basicRDS(rName, model, description string) string {
if description == "" {
description = "null"
} else {
description = strconv.Quote(description)
}

return acctest.ConfigCompose(testAccKnowledgeBase_baseRDS(rName, model), fmt.Sprintf(`
resource "aws_bedrockagent_knowledge_base" "test" {
name = %[1]q
role_arn = aws_iam_role.test.arn
description = %[3]s
knowledge_base_configuration {
vector_knowledge_base_configuration {
embedding_model_arn = "arn:${data.aws_partition.current.partition}:bedrock:${data.aws_region.current.name}::foundation-model/%[2]s"
Expand All @@ -598,7 +606,7 @@ resource "aws_bedrockagent_knowledge_base" "test" {
depends_on = [aws_iam_role_policy.test, null_resource.db_setup]
}
`, rName, model))
`, rName, model, description))
}

func testAccKnowledgeBaseConfig_tags1(rName, model, tag1Key, tag1Value string) string {
Expand Down

0 comments on commit f16b146

Please sign in to comment.