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: Fail fast when migration test is detecting TF_CLI_CONFIG_FILE #2266

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/testutil/mig/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

func SkipIfVersionBelow(tb testing.TB, minVersion string) {
tb.Helper()
validateConflictingEnvVars(tb)
Copy link
Member

Choose a reason for hiding this comment

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

do we need to call it here? I assume that checkLastVersion will be called at some point in a mig test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I found some examples where only acc pre checks are used, e.g., here.

Copy link
Member

Choose a reason for hiding this comment

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

oh i see, so we have some inconsistencies as we should call checkLastVersion before calling versionConstraint, but it's not happening in the example you're mentioning.

mig.ExternalProviders calls versionConstraint but checkLastVersion is not called because the test is missing a mig precheck

Copy link
Member

Choose a reason for hiding this comment

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

all mig tests should call a mig precheck but not sure if it's easy to enforce

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it would be nice if we could enforce it.
For now, I pefer keeping the validateConflictingEnvVars in the SkipIfVersionBelow 👍

if !IsProviderVersionAtLeast(minVersion) {
tb.Skipf("Skipping because version %s below %s", versionConstraint(), minVersion)
}
Expand All @@ -32,6 +33,7 @@ func ExternalProvidersWithAWS() map[string]resource.ExternalProvider {

func checkLastVersion(tb testing.TB) {
tb.Helper()
validateConflictingEnvVars(tb)
if os.Getenv("MONGODB_ATLAS_LAST_VERSION") == "" {
tb.Fatal("`MONGODB_ATLAS_LAST_VERSION` must be set for migration acceptance testing")
}
Expand All @@ -40,3 +42,10 @@ func checkLastVersion(tb testing.TB) {
func versionConstraint() string {
return os.Getenv("MONGODB_ATLAS_LAST_VERSION")
}

func validateConflictingEnvVars(tb testing.TB) {
tb.Helper()
if os.Getenv("TF_CLI_CONFIG_FILE") != "" {
tb.Fatal("found `TF_CLI_CONFIG_FILE` in env-var when running migration tests, this might override the terraform provider for MONGODB_ATLAS_LAST_VERSION and instead use local latest build!")
}
}