Skip to content

Commit

Permalink
TestAccSearchIndex_withWaitForIndexBuildCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Dec 13, 2024
1 parent 3eda763 commit 5b0fbe3
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions internal/service/searchindex/resource_search_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ func TestAccSearchIndex_basic(t *testing.T) {
resource.ParallelTest(t, *basicTestCase(t))
}

func TestAccSearchIndex_withWaitForIndexBuildCompletion(t *testing.T) {
var (
projectID, clusterName = acc.ClusterNameExecution(t)
indexName = acc.RandomName()
databaseName = acc.RandomName()
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, clusterName, indexName, "", databaseName, "", true),
Check: checkBasic(projectID, clusterName, indexName, "", databaseName, ""),
},
},
})
}

func TestAccSearchIndex_withSearchType(t *testing.T) {
var (
projectID, clusterName = acc.ClusterNameExecution(t)
Expand All @@ -28,7 +47,7 @@ func TestAccSearchIndex_withSearchType(t *testing.T) {
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, clusterName, indexName, "search", databaseName, ""),
Config: configBasic(projectID, clusterName, indexName, "search", databaseName, "", false),
Check: checkBasic(projectID, clusterName, indexName, "search", databaseName, ""),
},
},
Expand Down Expand Up @@ -163,11 +182,11 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, clusterName, indexName, "", databaseName, ""),
Config: configBasic(projectID, clusterName, indexName, "", databaseName, "", false),
Check: checkBasic(projectID, clusterName, indexName, "", databaseName, ""),
},
{
Config: configBasic(projectID, clusterName, indexName, "", databaseName, ""),
Config: configBasic(projectID, clusterName, indexName, "", databaseName, "", false),
ResourceName: resourceName,
ImportStateIdFunc: importStateIDFunc(resourceName),
ImportState: true,
Expand Down Expand Up @@ -214,7 +233,7 @@ func storedSourceTestCase(tb testing.TB, storedSource string) *resource.TestCase
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, clusterName, indexName, "search", databaseName, storedSource),
Config: configBasic(projectID, clusterName, indexName, "search", databaseName, storedSource, false),
Check: checkBasic(projectID, clusterName, indexName, "search", databaseName, storedSource),
},
},
Expand All @@ -234,11 +253,11 @@ func storedSourceTestCaseUpdate(tb testing.TB, searchType string) *resource.Test
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, clusterName, indexName, searchType, databaseName, "false"),
Config: configBasic(projectID, clusterName, indexName, searchType, databaseName, "false", false),
Check: checkBasic(projectID, clusterName, indexName, searchType, databaseName, "false"),
},
{
Config: configBasic(projectID, clusterName, indexName, searchType, databaseName, "true"),
Config: configBasic(projectID, clusterName, indexName, searchType, databaseName, "true", false),
Check: checkBasic(projectID, clusterName, indexName, searchType, databaseName, "true"),
},
},
Expand Down Expand Up @@ -306,7 +325,7 @@ func checkExists(resourceName string) resource.TestCheckFunc {
}
}

func configBasic(projectID, clusterName, indexName, indexType, databaseName, storedSource string) string {
func configBasic(projectID, clusterName, indexName, indexType, databaseName, storedSource string, waitForIndexBuildCompletion bool) string {
var extra string
if indexType != "" {
extra += fmt.Sprintf("type=%q\n", indexType)
Expand All @@ -318,6 +337,9 @@ func configBasic(projectID, clusterName, indexName, indexType, databaseName, sto
extra += fmt.Sprintf("stored_source= <<-EOF\n%s\nEOF\n", storedSource)
}
}
if waitForIndexBuildCompletion {
extra += "wait_for_index_build_completion=true\n"
}

return fmt.Sprintf(`
resource "mongodbatlas_search_index" "test" {
Expand Down

0 comments on commit 5b0fbe3

Please sign in to comment.