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

chore: Adds mig tests and refactor - searchindex #2065

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 25 additions & 1 deletion .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
cluster_outage_simulation: ${{ steps.filter.outputs.cluster_outage_simulation == 'true' || env.mustTrigger == 'true' }}
cluster: ${{ steps.filter.outputs.cluster == 'true' || env.mustTrigger == 'true' }}
ldap: ${{ steps.filter.outputs.ldap == 'true' || env.mustTrigger == 'true' }}
search_index: ${{ steps.filter.outputs.search_index == 'true' || env.mustTrigger == 'true' }}
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
Expand Down Expand Up @@ -148,7 +149,9 @@ jobs:
ldap:
- 'internal/service/ldapconfiguration/*.go'
- 'internal/service/ldapverify/*.go'

search_index:
- 'internal/service/searchindex/*.go'

project:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.project == 'true' || inputs.test_group == 'project' }}
Expand Down Expand Up @@ -544,3 +547,24 @@ jobs:
./internal/service/ldapconfiguration
./internal/service/ldapverify
run: make testacc
search_index:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.search_index == 'true' || inputs.test_group == 'search_index' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Migration Tests
env:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
ACCTEST_PACKAGES: ./internal/service/searchindex
run: make testacc

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package searchindex_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestMigSearchIndexRS_basic(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove RS from test names if we're testing resource and datasource together

var (
clusterInfo = acc.GetClusterInfo(t, nil)
indexName = acc.RandomName()
databaseName = acc.RandomName()
config = configBasic(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr, false)
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: config,
ExternalProviders: mig.ExternalProviders(),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", indexName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.ClusterName),
resource.TestCheckResourceAttr(resourceName, "database", databaseName),
resource.TestCheckResourceAttr(resourceName, "collection_name", collectionName),
resource.TestCheckResourceAttr(resourceName, "search_analyzer", searchAnalyzer),
resource.TestCheckResourceAttr(resourceName, "type", ""),
),
},
mig.TestStepCheckEmptyPlan(config),
},
})
}

func TestMigSearchIndexRS_withVector(t *testing.T) {
var (
clusterInfo = acc.GetClusterInfo(t, nil)
indexName = acc.RandomName()
databaseName = acc.RandomName()
config = configVector(clusterInfo.ProjectIDStr, indexName, databaseName, clusterInfo.ClusterNameStr, clusterInfo.ClusterTerraformStr)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroySearchIndex,
Steps: []resource.TestStep{
{
Config: config,
ExternalProviders: mig.ExternalProviders(),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", indexName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "cluster_name", clusterInfo.ClusterName),
resource.TestCheckResourceAttr(resourceName, "database", databaseName),
resource.TestCheckResourceAttr(resourceName, "collection_name", collectionName),
resource.TestCheckResourceAttr(resourceName, "type", "vectorSearch"),
resource.TestCheckResourceAttrSet(resourceName, "fields"),
resource.TestCheckResourceAttrWith(resourceName, "fields", acc.JSONEquals(fieldsJSON)),
),
},
mig.TestStepCheckEmptyPlan(config),
},
})
}
Loading