Skip to content

Commit 9f554cc

Browse files
authored
[Internal] Use TEST_ENVIRONMENT_TYPE for acceptance test environment detection (#5476)
## Changes <!-- Summary of your changes that are easy to understand --> - Replaces ad-hoc environment variable checks (`DATABRICKS_ACCOUNT_ID`, `TEST_METASTORE_ID`) with a single `TEST_ENVIRONMENT_TYPE` variable for determining test execution context - Introduces `skipIfNotEnvironmentType()` helper that centralizes skip logic for all four test levels: `ACCOUNT`, `WORKSPACE`, `UC_ACCOUNT`, `UC_WORKSPACE` - Simplifies `LoadWorkspaceEnv`, `LoadAccountEnv`, `LoadUcwsEnv`, and `LoadUcacctEnv` to one-liners ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> NO_CHANGELOG=true
1 parent 4c7a3b9 commit 9f554cc

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

internal/acceptance/init.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,36 +436,37 @@ func setDebugLogger() {
436436

437437
func LoadWorkspaceEnv(t *testing.T) {
438438
initTest(t, "workspace")
439-
if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" {
440-
Skipf(t)("Skipping workspace test on account level")
441-
}
439+
skipIfNotEnvironmentType(t, "WORKSPACE", "UC_WORKSPACE")
442440
}
443441

444442
func LoadAccountEnv(t *testing.T) {
445443
initTest(t, "account")
446-
if os.Getenv("DATABRICKS_ACCOUNT_ID") == "" {
447-
Skipf(t)("Skipping account test on workspace level")
448-
}
444+
skipIfNotEnvironmentType(t, "ACCOUNT", "UC_ACCOUNT")
449445
}
450446

451447
func LoadUcwsEnv(t *testing.T) {
452448
initTest(t, "ucws")
453-
if os.Getenv("TEST_METASTORE_ID") == "" {
454-
Skipf(t)("Skipping non-Unity Catalog test")
455-
}
456-
if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" {
457-
Skipf(t)("Skipping workspace test on account level")
458-
}
449+
skipIfNotEnvironmentType(t, "UC_WORKSPACE")
459450
}
460451

461452
func LoadUcacctEnv(t *testing.T) {
462453
initTest(t, "ucacct")
463-
if os.Getenv("TEST_METASTORE_ID") == "" {
464-
Skipf(t)("Skipping non-Unity Catalog test")
454+
skipIfNotEnvironmentType(t, "UC_ACCOUNT")
455+
}
456+
457+
// skipIfNotEnvironmentType skips the test if TEST_ENVIRONMENT_TYPE doesn't match any of the expected types.
458+
// TEST_ENVIRONMENT_TYPE values: "ACCOUNT", "WORKSPACE", "UC_ACCOUNT", "UC_WORKSPACE".
459+
func skipIfNotEnvironmentType(t *testing.T, expectedTypes ...string) {
460+
envType := os.Getenv("TEST_ENVIRONMENT_TYPE")
461+
if envType == "" {
462+
Skipf(t)("Skipping test because TEST_ENVIRONMENT_TYPE is not set")
465463
}
466-
if os.Getenv("DATABRICKS_ACCOUNT_ID") == "" {
467-
Skipf(t)("Skipping account test on workspace level")
464+
for _, expected := range expectedTypes {
465+
if envType == expected {
466+
return
467+
}
468468
}
469+
Skipf(t)("Skipping %s test in %s environment", strings.Join(expectedTypes, "/"), envType)
469470
}
470471

471472
func IsAws(t *testing.T) bool {

0 commit comments

Comments
 (0)