Skip to content

Commit

Permalink
Expose several integration test helpers for use in plugin framework i…
Browse files Browse the repository at this point in the history
…ntegration tests
  • Loading branch information
mgyucht committed Dec 11, 2024
1 parent b1f0847 commit 07a77bc
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 88 deletions.
4 changes: 2 additions & 2 deletions internal/acceptance/account_rule_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Application ID is mandatory in Azure today.
func getServicePrincipalResource(t *testing.T) string {
if isAzure(t) {
if IsAzure(t) {
return `
resource "databricks_service_principal" "this" {
application_id = "{var.RANDOM_UUID}"
Expand All @@ -30,7 +30,7 @@ func getServicePrincipalResource(t *testing.T) string {
}

func TestMwsAccAccountServicePrincipalRuleSetsFullLifeCycle(t *testing.T) {
loadAccountEnv(t)
LoadAccountEnv(t)
spResource := getServicePrincipalResource(t)
AccountLevel(t, Step{
Template: spResource + `
Expand Down
8 changes: 4 additions & 4 deletions internal/acceptance/budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (
)

func TestMwsAccBudgetCreate(t *testing.T) {
loadAccountEnv(t)
if isGcp(t) {
LoadAccountEnv(t)
if IsGcp(t) {
skipf(t)("not available on GCP")
}
AccountLevel(t, Step{
Expand All @@ -51,8 +51,8 @@ func TestMwsAccBudgetCreate(t *testing.T) {
}

func TestMwsAccBudgetUpdate(t *testing.T) {
loadAccountEnv(t)
if isGcp(t) {
LoadAccountEnv(t)
if IsGcp(t) {
skipf(t)("not available on GCP")
}
AccountLevel(t, Step{
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestUcAccCatalog(t *testing.T) {
loadUcwsEnv(t)
LoadUcwsEnv(t)
UnityWorkspaceLevel(t, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestUcAccCatalogIsolated(t *testing.T) {
}

func TestUcAccCatalogUpdate(t *testing.T) {
loadUcwsEnv(t)
LoadUcwsEnv(t)
UnityWorkspaceLevel(t, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func awsClusterTemplate(availability string) string {
}

func TestAccClusterResource_CreateAndUpdateAwsAttributes(t *testing.T) {
loadWorkspaceEnv(t)
if isAws(t) {
LoadWorkspaceEnv(t)
if IsAws(t) {
WorkspaceLevel(t, Step{
Template: awsClusterTemplate("SPOT"),
}, Step{
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

func TestUcAccCredential(t *testing.T) {
loadUcwsEnv(t)
if isAws(t) {
LoadUcwsEnv(t)
if IsAws(t) {
UnityWorkspaceLevel(t, Step{
Template: `
resource "databricks_credential" "external" {
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/custom_app_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var (
)

func TestMwsAccCustomAppIntegrationCreate(t *testing.T) {
loadAccountEnv(t)
LoadAccountEnv(t)
AccountLevel(t, Step{
Template: fmt.Sprintf(customAppIntegrationTemplate, "30"),
})
}

func TestMwsAccCustomAppIntegrationUpdate(t *testing.T) {
loadAccountEnv(t)
LoadAccountEnv(t)
AccountLevel(t, Step{
Template: fmt.Sprintf(customAppIntegrationTemplate, "30"),
}, Step{
Expand Down
16 changes: 8 additions & 8 deletions internal/acceptance/data_current_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func checkCurrentConfig(t *testing.T, cloudType string, isAccount string) func(s
}

func TestAccDataCurrentConfig(t *testing.T) {
loadWorkspaceEnv(t)
if isAws(t) {
LoadWorkspaceEnv(t)
if IsAws(t) {
WorkspaceLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "aws", "false"),
})
} else if isAzure(t) {
} else if IsAzure(t) {
WorkspaceLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "azure", "false"),
})
} else if isGcp(t) {
} else if IsGcp(t) {
WorkspaceLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "gcp", "false"),
Expand All @@ -42,18 +42,18 @@ func TestAccDataCurrentConfig(t *testing.T) {
}

func TestMwsAccDataCurrentConfig(t *testing.T) {
loadAccountEnv(t)
if isAws(t) {
LoadAccountEnv(t)
if IsAws(t) {
AccountLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "aws", "true"),
})
} else if isAzure(t) {
} else if IsAzure(t) {
AccountLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "azure", "true"),
})
} else if isGcp(t) {
} else if IsGcp(t) {
AccountLevel(t, Step{
Template: `data "databricks_current_config" "this" {}`,
Check: checkCurrentConfig(t, "gcp", "true"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

func TestAccDataSourceMwsNetworkConnectivityConfigTest(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
LoadWorkspaceEnv(t)
if IsGcp(t) {
skipf(t)("GCP not supported")
}
var sourceRegion string
if isAzure(t) {
if IsAzure(t) {
sourceRegion = "eastus2"
} else if isAws(t) {
} else if IsAws(t) {
sourceRegion = "us-east-2"
}
AccountLevel(t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

func TestAccDataSourceMwsNetworkConnectivityConfigsTest(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
LoadWorkspaceEnv(t)
if IsGcp(t) {
skipf(t)("GCP not supported")
}
var region string
if isAzure(t) {
if IsAzure(t) {
region = "eastus2"
} else if isAws(t) {
} else if IsAws(t) {
region = "us-east-2"
}
AccountLevel(t,
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/entitlements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func makePreconfig(t *testing.T, r entitlementResource) func() {
}

func entitlementsTest(t *testing.T, f func(*testing.T, entitlementResource)) {
loadWorkspaceEnv(t)
LoadWorkspaceEnv(t)
sp := &servicePrincipalResource{}
if isAzure(t) {
if IsAzure(t) {
// A long-lived application is used in Azure.
sp.applicationId = GetEnvOrSkipTest(t, "ACCOUNT_LEVEL_SERVICE_PRINCIPAL_ID")
sp.cleanup = false
Expand Down
22 changes: 11 additions & 11 deletions internal/acceptance/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ func init() {
}

func WorkspaceLevel(t *testing.T, steps ...Step) {
loadWorkspaceEnv(t)
LoadWorkspaceEnv(t)
run(t, steps)
}

func AccountLevel(t *testing.T, steps ...Step) {
loadAccountEnv(t)
LoadAccountEnv(t)
run(t, steps)
}

func UnityWorkspaceLevel(t *testing.T, steps ...Step) {
loadUcwsEnv(t)
LoadUcwsEnv(t)
run(t, steps)
}

func UnityAccountLevel(t *testing.T, steps ...Step) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
run(t, steps)
}

Expand Down Expand Up @@ -359,21 +359,21 @@ func setDebugLogger() {
}
}

func loadWorkspaceEnv(t *testing.T) {
func LoadWorkspaceEnv(t *testing.T) {
initTest(t, "workspace")
if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" {
skipf(t)("Skipping workspace test on account level")
}
}

func loadAccountEnv(t *testing.T) {
func LoadAccountEnv(t *testing.T) {
initTest(t, "account")
if os.Getenv("DATABRICKS_ACCOUNT_ID") == "" {
skipf(t)("Skipping account test on workspace level")
}
}

func loadUcwsEnv(t *testing.T) {
func LoadUcwsEnv(t *testing.T) {
initTest(t, "ucws")
if os.Getenv("TEST_METASTORE_ID") == "" {
skipf(t)("Skipping non-Unity Catalog test")
Expand All @@ -383,7 +383,7 @@ func loadUcwsEnv(t *testing.T) {
}
}

func loadUcacctEnv(t *testing.T) {
func LoadUcacctEnv(t *testing.T) {
initTest(t, "ucacct")
if os.Getenv("TEST_METASTORE_ID") == "" {
skipf(t)("Skipping non-Unity Catalog test")
Expand All @@ -393,17 +393,17 @@ func loadUcacctEnv(t *testing.T) {
}
}

func isAws(t *testing.T) bool {
func IsAws(t *testing.T) bool {
awsCloudEnvs := []string{"MWS", "aws", "ucws", "ucacct"}
return isCloudEnvInList(t, awsCloudEnvs)
}

func isAzure(t *testing.T) bool {
func IsAzure(t *testing.T) bool {
azureCloudEnvs := []string{"azure", "azure-ucacct"}
return isCloudEnvInList(t, azureCloudEnvs)
}

func isGcp(t *testing.T) bool {
func IsGcp(t *testing.T) bool {
gcpCloudEnvs := []string{"gcp-accounts", "gcp-ucacct", "gcp-ucws", "gcp"}
return isCloudEnvInList(t, gcpCloudEnvs)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func TestAccJobRunAsUser(t *testing.T) {
}

func TestUcAccJobRunAsServicePrincipal(t *testing.T) {
loadUcwsEnv(t)
LoadUcwsEnv(t)
spId := GetEnvOrSkipTest(t, "ACCOUNT_LEVEL_SERVICE_PRINCIPAL_ID")
UnityWorkspaceLevel(t, Step{
Template: runAsTemplate(`service_principal_name = "` + spId + `"`),
Expand All @@ -373,7 +373,7 @@ func getRunAsAttribute(t *testing.T, ctx context.Context) string {
}

func TestUcAccJobRunAsMutations(t *testing.T) {
loadUcwsEnv(t)
LoadUcwsEnv(t)
spId := GetEnvOrSkipTest(t, "ACCOUNT_LEVEL_SERVICE_PRINCIPAL_ID")
// Note: the attribute must match the type of principal that the test is run as.
ctx := context.Background()
Expand Down
22 changes: 11 additions & 11 deletions internal/acceptance/metastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ import (
)

func getStorageRoot(t *testing.T) string {
if isAws(t) {
if IsAws(t) {
return "s3://{env.TEST_BUCKET}/test{var.RANDOM}"
} else if isAzure(t) {
} else if IsAzure(t) {
return "abfss://{var.RANDOM}@{var.RANDOM}/"
} else if isGcp(t) {
} else if IsGcp(t) {
return "gs://{var.RANDOM}/metastore"
}
return ""
}

func getRegion(t *testing.T) string {
if isAws(t) {
if IsAws(t) {
return "us-east-1"
} else if isAzure(t) {
} else if IsAzure(t) {
return "eastus"
} else if isGcp(t) {
} else if IsGcp(t) {
return "us-east1"
}
return ""
}

func TestUcAccRootlessMetastore(t *testing.T) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
runMetastoreTest(t, map[string]any{
"region": getRegion(t),
})
}

func TestUcAccMetastore(t *testing.T) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
runMetastoreTest(t, map[string]any{
"storage_root": getStorageRoot(t),
"region": getRegion(t),
})
}

func TestUcAccMetastoreDeltaSharing(t *testing.T) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
runMetastoreTest(t, map[string]any{
"storage_root": getStorageRoot(t),
"region": getRegion(t),
Expand All @@ -58,7 +58,7 @@ func TestUcAccMetastoreDeltaSharing(t *testing.T) {
}

func TestUcAccMetastoreDeltaSharingInfiniteLifetime(t *testing.T) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
runMetastoreTest(t, map[string]any{
"storage_root": getStorageRoot(t),
"region": getRegion(t),
Expand All @@ -68,7 +68,7 @@ func TestUcAccMetastoreDeltaSharingInfiniteLifetime(t *testing.T) {
}

func TestUcAccMetastoreWithOwnerUpdates(t *testing.T) {
loadUcacctEnv(t)
LoadUcacctEnv(t)
runMetastoreTestWithOwnerUpdates(t, map[string]any{
"storage_root": getStorageRoot(t),
"region": getRegion(t),
Expand Down
12 changes: 6 additions & 6 deletions internal/acceptance/model_serving_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

func TestAccModelServing(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
LoadWorkspaceEnv(t)
if IsGcp(t) {
skipf(t)("not available on GCP")
}

Expand Down Expand Up @@ -86,8 +86,8 @@ func TestAccModelServing(t *testing.T) {
}

func TestUcAccModelServingProvisionedThroughput(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
LoadWorkspaceEnv(t)
if IsGcp(t) {
skipf(t)("not available on GCP")
}

Expand Down Expand Up @@ -161,8 +161,8 @@ func TestUcAccModelServingProvisionedThroughput(t *testing.T) {
}

func TestAccModelServingExternalModel(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
LoadWorkspaceEnv(t)
if IsGcp(t) {
skipf(t)("not available on GCP")
}

Expand Down
Loading

0 comments on commit 07a77bc

Please sign in to comment.