Skip to content

Commit 93e76c4

Browse files
lantoliEspenAlbert
andauthored
test: Migration tests for all SDKv2 and TPF paths (#3194)
* migTest and env var MONGODB_ATLAS_TEST_SDKV2_TO_TPF * refactor IsTestSDKv2ToTPF * add MONGODB_ATLAS_LAST_VERSION * keep HTTP_MOCKER_CAPTURE * keep HTTP_MOCKER_CAPTURE * make sure TPF is enabled in setupTestsSDKv2ToTPF * Update internal/testutil/acc/shared_resource.go Co-authored-by: Espen Albert <[email protected]> --------- Co-authored-by: Espen Albert <[email protected]>
1 parent 94c9d2d commit 93e76c4

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

.github/workflows/acceptance-tests-runner.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,40 @@ jobs:
412412
run: make testmact
413413
- name: Acceptance Tests
414414
env:
415-
MONGODB_ATLAS_LAST_VERSION: '1.28.0' # Fix mig test version until CLOUDP-296406 is resolved
415+
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
416416
HTTP_MOCKER_CAPTURE: 'true'
417417
ACCTEST_REGEX_RUN: ${{ inputs.reduced_tests && '^TestAccMockable' || env.ACCTEST_REGEX_RUN }}
418418
ACCTEST_PACKAGES: |
419419
./internal/service/advancedcluster
420420
./internal/service/advancedclustertpf
421421
run: make testacc
422422

423+
advanced_cluster_tpf_mig_from_sdkv2:
424+
needs: [ change-detection, get-provider-version ]
425+
if: ${{ inputs.reduced_tests == false && (needs.change-detection.outputs.advanced_cluster_tpf == 'true' || inputs.test_group == 'advanced_cluster_tpf') }}
426+
env:
427+
MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER: 'true'
428+
MONGODB_ATLAS_TEST_SDKV2_TO_TPF: 'true'
429+
runs-on: ubuntu-latest
430+
permissions: {}
431+
steps:
432+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
433+
with:
434+
ref: ${{ inputs.ref || github.ref }}
435+
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34
436+
with:
437+
go-version-file: 'go.mod'
438+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
439+
with:
440+
terraform_version: ${{ inputs.terraform_version }}
441+
terraform_wrapper: false
442+
- name: Acceptance Tests
443+
env:
444+
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
445+
ACCTEST_REGEX_RUN: '^TestMig'
446+
ACCTEST_PACKAGES: ./internal/service/advancedcluster
447+
run: make testacc
448+
423449
assume_role:
424450
needs: [ change-detection, get-provider-version ]
425451
if: ${{ needs.change-detection.outputs.assume_role == 'true' || inputs.test_group == 'assume_role' }}

internal/service/advancedcluster/resource_advanced_cluster_migration_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
88

9+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
910
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
1011
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
1112
)
@@ -14,29 +15,24 @@ import (
1415
const versionBeforeISSRelease = "1.17.6"
1516

1617
func TestMigAdvancedCluster_replicaSetAWSProvider(t *testing.T) {
17-
testCase := replicaSetAWSProviderTestCase(t, false)
18-
mig.CreateAndRunTest(t, &testCase)
18+
migTest(t, replicaSetAWSProviderTestCase)
1919
}
2020

2121
func TestMigAdvancedCluster_replicaSetMultiCloud(t *testing.T) {
22-
testCase := replicaSetMultiCloudTestCase(t, false)
23-
mig.CreateAndRunTest(t, &testCase)
22+
migTest(t, replicaSetMultiCloudTestCase)
2423
}
2524

2625
func TestMigAdvancedCluster_singleShardedMultiCloud(t *testing.T) {
27-
testCase := singleShardedMultiCloudTestCase(t, false)
28-
mig.CreateAndRunTest(t, &testCase)
26+
migTest(t, singleShardedMultiCloudTestCase)
2927
}
3028

3129
func TestMigAdvancedCluster_symmetricGeoShardedOldSchema(t *testing.T) {
32-
testCase := symmetricGeoShardedOldSchemaTestCase(t, false)
33-
mig.CreateAndRunTest(t, &testCase)
30+
migTest(t, symmetricGeoShardedOldSchemaTestCase)
3431
}
3532

3633
func TestMigAdvancedCluster_asymmetricShardedNewSchema(t *testing.T) {
3734
mig.SkipIfVersionBelow(t, "1.23.0") // version where sharded cluster tier auto-scaling was introduced
38-
testCase := asymmetricShardedNewSchemaTestCase(t, false)
39-
mig.CreateAndRunTest(t, &testCase)
35+
migTest(t, asymmetricShardedNewSchemaTestCase)
4036
}
4137

4238
func TestMigAdvancedCluster_replicaSetAWSProviderUpdate(t *testing.T) {
@@ -282,3 +278,15 @@ func configPartialAdvancedConfig(projectID, clusterName, extraArgs, autoScaling
282278
}
283279
`, projectID, clusterName, extraArgs, autoScaling)
284280
}
281+
282+
// migTest is a helper function to run migration tests in normal case (SDKv2 -> SDKv2, TPF -> TPF), or in mixed case (SDKv2 -> TPF).
283+
func migTest(t *testing.T, testCaseFunc func(t *testing.T, isAcc bool) resource.TestCase) {
284+
t.Helper()
285+
isAcc := config.PreviewProviderV2AdvancedCluster()
286+
if acc.IsTestSDKv2ToTPF() {
287+
isAcc = false
288+
t.Log("Running test SDKv2 to TPF")
289+
}
290+
testCase := testCaseFunc(t, isAcc)
291+
mig.CreateAndRunTest(t, &testCase)
292+
}

internal/testutil/acc/advanced_cluster_preview_provider_v2.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package acc
22

33
import (
4+
"os"
5+
"strconv"
46
"strings"
57
"testing"
68

@@ -14,6 +16,12 @@ import (
1416
"github.com/stretchr/testify/assert"
1517
)
1618

19+
// IsTestSDKv2ToTPF returns if we want to run migration tests from SDKv2 to TPF.
20+
func IsTestSDKv2ToTPF() bool {
21+
env, _ := strconv.ParseBool(os.Getenv("MONGODB_ATLAS_TEST_SDKV2_TO_TPF"))
22+
return env
23+
}
24+
1725
func CheckRSAndDSPreviewProviderV2(isAcc bool, resourceName string, dataSourceName, pluralDataSourceName *string, attrsSet []string, attrsMap map[string]string, extra ...resource.TestCheckFunc) resource.TestCheckFunc {
1826
modifiedSet := ConvertToPreviewProviderV2AttrsSet(isAcc, attrsSet)
1927
modifiedMap := ConvertToPreviewProviderV2AttrsMap(isAcc, attrsMap)

internal/testutil/acc/shared_resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package acc
22

33
import (
44
"fmt"
5+
"os"
56
"sync"
67
"testing"
78
"time"
89

10+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
911
"github.com/stretchr/testify/require"
1012
)
1113

@@ -17,6 +19,7 @@ const (
1719
// It returns the cleanup function that must be called at the end of TestMain.
1820
func SetupSharedResources() func() {
1921
sharedInfo.init = true
22+
setupTestsSDKv2ToTPF()
2023
return cleanupSharedResources
2124
}
2225

@@ -166,3 +169,11 @@ func NextProjectIDClusterName(totalNodeCount int, projectCreator func(string) st
166169
}
167170
return project.id, RandomClusterName()
168171
}
172+
173+
// setupTestsSDKv2ToTPF sets the Preview environment variable to false so the previous version in migration tests uses SDKv2.
174+
// However the current version will use TPF as the variable is only read once during import when it was true.
175+
func setupTestsSDKv2ToTPF() {
176+
if IsTestSDKv2ToTPF() && config.PreviewProviderV2AdvancedCluster() {
177+
os.Setenv(config.PreviewProviderV2AdvancedClusterEnvVar, "false")
178+
}
179+
}

0 commit comments

Comments
 (0)