Skip to content

Commit c5bb35f

Browse files
committed
Use TEST_ENVIRONMENT_TYPE for integration test filtering
Port of Python SDK PR #1317. Add support for the TEST_ENVIRONMENT_TYPE environment variable to control which integration tests run. Supported values: WORKSPACE, UC_WORKSPACE, ACCOUNT, UC_ACCOUNT. Falls back to the existing DATABRICKS_ACCOUNT_ID-based logic when not set. Co-authored-by: Isaac
1 parent 8c24b9f commit c5bb35f

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

internal/init_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ func init() {
3131
}
3232
}
3333

34+
// testEnvironmentType returns the value of the TEST_ENVIRONMENT_TYPE
35+
// environment variable, which controls integration test filtering.
36+
func testEnvironmentType() string {
37+
return os.Getenv("TEST_ENVIRONMENT_TYPE")
38+
}
39+
3440
// prelude for all workspace-level tests
3541
func workspaceTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) {
3642
loadDebugEnvIfRunsFromIDE(t, "workspace")
3743
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
38-
if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" {
39-
skipf(t)("Skipping workspace test on account level")
44+
if envType := testEnvironmentType(); envType != "" && envType != "WORKSPACE" && envType != "UC_WORKSPACE" {
45+
skipf(t)("Skipping workspace test: TEST_ENVIRONMENT_TYPE=%s", envType)
4046
}
4147
t.Parallel()
4248
ctx := context.Background()
@@ -46,8 +52,8 @@ func workspaceTest(t *testing.T) (context.Context, *databricks.WorkspaceClient)
4652
// prelude for all workspace-level UC tests
4753
func ucwsTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) {
4854
loadDebugEnvIfRunsFromIDE(t, "ucws")
49-
if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" {
50-
skipf(t)("Skipping workspace test on account level")
55+
if envType := testEnvironmentType(); envType != "" && envType != "UC_WORKSPACE" {
56+
skipf(t)("Skipping UC workspace test: TEST_ENVIRONMENT_TYPE=%s", envType)
5157
}
5258
GetEnvOrSkipTest(t, "TEST_METASTORE_ID")
5359
t.Parallel()
@@ -91,6 +97,9 @@ func unifiedHostAccountTest(t *testing.T) (context.Context, *databricks.AccountC
9197
// prelude for all account-level tests
9298
func accountTest(t *testing.T) (context.Context, *databricks.AccountClient) {
9399
loadDebugEnvIfRunsFromIDE(t, "account")
100+
if envType := testEnvironmentType(); envType != "" && envType != "ACCOUNT" && envType != "UC_ACCOUNT" {
101+
skipf(t)("Skipping account test: TEST_ENVIRONMENT_TYPE=%s", envType)
102+
}
94103
cfg := &config.Config{
95104
AccountID: GetEnvOrSkipTest(t, "DATABRICKS_ACCOUNT_ID"),
96105
// Large timeout to support API calls that take long.
@@ -102,9 +111,6 @@ func accountTest(t *testing.T) (context.Context, *databricks.AccountClient) {
102111
if err != nil {
103112
skipf(t)("error: %s", err)
104113
}
105-
if cfg.HostType() == config.WorkspaceHost {
106-
skipf(t)("Not in account env: %s/%s", cfg.AccountID, cfg.Host)
107-
}
108114
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
109115
t.Parallel()
110116
ctx := context.Background()
@@ -115,16 +121,16 @@ func accountTest(t *testing.T) (context.Context, *databricks.AccountClient) {
115121
// prelude for all UC account-level tests
116122
func ucacctTest(t *testing.T) (context.Context, *databricks.AccountClient) {
117123
loadDebugEnvIfRunsFromIDE(t, "ucacct")
124+
if envType := testEnvironmentType(); envType != "" && envType != "UC_ACCOUNT" {
125+
skipf(t)("Skipping UC account test: TEST_ENVIRONMENT_TYPE=%s", envType)
126+
}
118127
cfg := &config.Config{
119128
AccountID: GetEnvOrSkipTest(t, "DATABRICKS_ACCOUNT_ID"),
120129
}
121130
err := cfg.EnsureResolved()
122131
if err != nil {
123132
skipf(t)("error: %s", err)
124133
}
125-
if cfg.HostType() == config.WorkspaceHost {
126-
skipf(t)("Not in account env: %s/%s", cfg.AccountID, cfg.Host)
127-
}
128134
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
129135
t.Parallel()
130136
ctx := context.Background()

0 commit comments

Comments
 (0)