Skip to content

Commit

Permalink
[Internal] Make test utils public and move integration test for quali…
Browse files Browse the repository at this point in the history
…ty monitor (#3993)

## Changes
<!-- Summary of your changes that are easy to understand -->
- Make `Step`, `WorkspaceLevel`, `AccountLevel`, `UnityWorkspaceLevel`,
`UnityAccountLevel` public
- Rename `init_test.go` to `init.go` because variables exported from
files ending with `_test` cannot be imported
- Moved integration test for quality monitor next to the resource
definition

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` run locally
- [x] relevant change in `docs/` folder
- [x] covered with integration tests in `internal/acceptance`
- [x] relevant acceptance tests are passing
- [x] using Go SDK
  • Loading branch information
edwardfeng-db authored Sep 4, 2024
1 parent a9c2001 commit bb871e1
Show file tree
Hide file tree
Showing 108 changed files with 539 additions and 488 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestExampleResourceCreate(t *testing.T) {
```go
func TestAccSecretAclResource(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `
resource "databricks_group" "ds" {
display_name = "data-scientists-{var.RANDOM}"
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestRunningRealTerraformWithFixtureBackend(t *testing.T) {
t.Setenv("DATABRICKS_HOST", client.Config.Host)
t.Setenv("DATABRICKS_TOKEN", client.Config.Token)

workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `resource "databricks_token" "this" {
lifetime_seconds = 6000
comment = "Testing token"
Expand Down
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 @@ -32,7 +32,7 @@ func getServicePrincipalResource(t *testing.T) string {
func TestMwsAccAccountServicePrincipalRuleSetsFullLifeCycle(t *testing.T) {
loadAccountEnv(t)
spResource := getServicePrincipalResource(t)
accountLevel(t, step{
AccountLevel(t, Step{
Template: spResource + `
resource "databricks_group" "this" {
display_name = "Group {var.RANDOM}"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestMwsAccAccountServicePrincipalRuleSetsFullLifeCycle(t *testing.T) {

func TestMwsAccAccountGroupRuleSetsFullLifeCycle(t *testing.T) {
username := qa.RandomEmail()
accountLevel(t, step{
AccountLevel(t, Step{
Template: `
resource "databricks_user" "this" {
user_name = "` + username + `"
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/artifact_allowlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestUcAccArtifactAllowlistResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: `
resource "databricks_artifact_allowlist" "init" {
artifact_type = "INIT_SCRIPT"
Expand Down
16 changes: 8 additions & 8 deletions internal/acceptance/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func TestUcAccCatalog(t *testing.T) {
loadUcwsEnv(t)
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.RANDOM}"
Expand All @@ -21,7 +21,7 @@ func TestUcAccCatalog(t *testing.T) {
}

func TestUcAccCatalogIsolated(t *testing.T) {
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -30,7 +30,7 @@ func TestUcAccCatalogIsolated(t *testing.T) {
purpose = "testing"
}
}`,
}, step{
}, Step{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -40,7 +40,7 @@ func TestUcAccCatalogIsolated(t *testing.T) {
purpose = "testing"
}
}`,
}, step{
}, Step{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -55,7 +55,7 @@ func TestUcAccCatalogIsolated(t *testing.T) {

func TestUcAccCatalogUpdate(t *testing.T) {
loadUcwsEnv(t)
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -65,7 +65,7 @@ func TestUcAccCatalogUpdate(t *testing.T) {
}
%s
}`, getPredictiveOptimizationSetting(t, true)),
}, step{
}, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -76,7 +76,7 @@ func TestUcAccCatalogUpdate(t *testing.T) {
%s
owner = "account users"
}`, getPredictiveOptimizationSetting(t, true)),
}, step{
}, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand All @@ -87,7 +87,7 @@ func TestUcAccCatalogUpdate(t *testing.T) {
%s
owner = "{env.TEST_DATA_ENG_GROUP}"
}`, getPredictiveOptimizationSetting(t, true)),
}, step{
}, Step{
Template: fmt.Sprintf(`
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.STICKY_RANDOM}"
Expand Down
8 changes: 4 additions & 4 deletions internal/acceptance/cluster_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestAccClusterPolicyResourceFullLifecycle(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `resource "databricks_cluster_policy" "external_metastore" {
name = "Terraform policy {var.RANDOM}"
definition = jsonencode({
Expand All @@ -15,7 +15,7 @@ func TestAccClusterPolicyResourceFullLifecycle(t *testing.T) {
}
})
}`,
}, step{
}, Step{
// renaming to a new random name
Template: `resource "databricks_cluster_policy" "external_metastore" {
name = "Terraform policy {var.RANDOM}"
Expand All @@ -30,7 +30,7 @@ func TestAccClusterPolicyResourceFullLifecycle(t *testing.T) {
}

func TestAccClusterPolicyResourceOverrideBuiltIn(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `resource "databricks_cluster_policy" "personal_vm" {
name = "Personal Compute"
policy_family_id = "personal-vm"
Expand All @@ -46,7 +46,7 @@ func TestAccClusterPolicyResourceOverrideBuiltIn(t *testing.T) {
}

func TestAccClusterPolicyResourceOverrideNew(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `resource "databricks_cluster_policy" "policyoverrideempty" {
policy_family_id = "personal-vm"
name = "Policy Override {var.RANDOM}"
Expand Down
22 changes: 11 additions & 11 deletions internal/acceptance/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestAccClusterResource_CreateClusterWithLibraries(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `data "databricks_spark_version" "latest" {
}
resource "databricks_cluster" "this" {
Expand Down Expand Up @@ -73,9 +73,9 @@ func singleNodeClusterTemplate(autoTerminationMinutes string) string {
}

func TestAccClusterResource_CreateSingleNodeCluster(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: singleNodeClusterTemplate("10"),
}, step{
}, Step{
Template: singleNodeClusterTemplate("20"),
})
}
Expand Down Expand Up @@ -103,16 +103,16 @@ func awsClusterTemplate(availability string) string {
func TestAccClusterResource_CreateAndUpdateAwsAttributes(t *testing.T) {
loadWorkspaceEnv(t)
if isAws(t) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: awsClusterTemplate("SPOT"),
}, step{
}, Step{
Template: awsClusterTemplate("SPOT_WITH_FALLBACK"),
})
}
}

func TestAccClusterResource_CreateAndNoWait(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: `data "databricks_spark_version" "latest" {
}
resource "databricks_cluster" "this" {
Expand All @@ -133,9 +133,9 @@ func TestAccClusterResource_CreateAndNoWait(t *testing.T) {
}

func TestAccClusterResource_WorkloadType(t *testing.T) {
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: testAccClusterResourceWorkloadTypeTemplate(""),
}, step{
}, Step{
Template: testAccClusterResourceWorkloadTypeTemplate(`
workload_type {
clients {
Expand All @@ -147,7 +147,7 @@ func TestAccClusterResource_WorkloadType(t *testing.T) {
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.jobs", "true"),
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.notebooks", "true"),
),
}, step{
}, Step{
Template: testAccClusterResourceWorkloadTypeTemplate(`
workload_type {
clients {
Expand All @@ -159,7 +159,7 @@ func TestAccClusterResource_WorkloadType(t *testing.T) {
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.jobs", "false"),
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.notebooks", "false"),
),
}, step{
}, Step{
Template: testAccClusterResourceWorkloadTypeTemplate(`
workload_type {
clients { }
Expand All @@ -168,7 +168,7 @@ func TestAccClusterResource_WorkloadType(t *testing.T) {
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.jobs", "true"),
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.0.clients.0.notebooks", "true"),
),
}, step{
}, Step{
Template: testAccClusterResourceWorkloadTypeTemplate(``),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("databricks_cluster.this", "workload_type.#", "0"),
Expand Down
10 changes: 5 additions & 5 deletions internal/acceptance/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ func connectionTemplateWithoutOwner() string {
`
}
func TestUcAccConnectionsResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "account users"),
}, step{
}, Step{
Template: connectionTemplateWithOwner("test.mysql.database.aws.com", "account users"),
}, step{
}, Step{
Template: connectionTemplateWithOwner("test.mysql.database.azure.com", "{env.TEST_METASTORE_ADMIN_GROUP_NAME}"),
})
}

func TestUcAccConnectionsWithoutOwnerResourceFullLifecycle(t *testing.T) {
unityWorkspaceLevel(t, step{
UnityWorkspaceLevel(t, Step{
Template: connectionTemplateWithoutOwner(),
}, step{
}, Step{
Template: connectionTemplateWithoutOwner(),
})
}
28 changes: 14 additions & 14 deletions internal/acceptance/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (t *templateStruct) SetAttributes(mapper map[string]string) templateStruct
func TestAccBasicDashboard(t *testing.T) {
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"display_name": displayName,
"warehouse_id": "{env.TEST_DEFAULT_WAREHOUSE_ID}",
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestAccBasicDashboard(t *testing.T) {
func TestAccDashboardWithSerializedJSON(t *testing.T) {
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"display_name": displayName,
"warehouse_id": "{env.TEST_DEFAULT_WAREHOUSE_ID}",
Expand All @@ -142,7 +142,7 @@ func TestAccDashboardWithSerializedJSON(t *testing.T) {
require.NoError(t, err)
return nil
}),
}, step{
}, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"serialized_dashboard": `{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page Modified\"}]}`,
"embed_credentials": "true",
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestAccDashboardWithFilePath(t *testing.T) {
fileName := tmpDir + "/Dashboard.json"
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
PreConfig: func() {
os.Mkdir(tmpDir, 0755)
os.WriteFile(fileName, []byte("{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page\"}]}"), 0644)
Expand All @@ -200,7 +200,7 @@ func TestAccDashboardWithFilePath(t *testing.T) {
require.NoError(t, err)
return nil
}),
}, step{
}, Step{
PreConfig: func() {
os.WriteFile(fileName, []byte("{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page Modified\"}]}"), 0644)
},
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestAccDashboardWithNoChange(t *testing.T) {
initial_update_time := ""
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"display_name": displayName,
"warehouse_id": "{env.TEST_DEFAULT_WAREHOUSE_ID}",
Expand All @@ -254,7 +254,7 @@ func TestAccDashboardWithNoChange(t *testing.T) {
initial_update_time = dashboard.UpdateTime
return nil
}),
}, step{
}, Step{
Template: makeTemplate(template),
Check: resourceCheck("databricks_dashboard.d1", func(ctx context.Context, client *common.DatabricksClient, id string) error {
w, err := client.WorkspaceClient()
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestAccDashboardWithRemoteChange(t *testing.T) {
etag := ""
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"display_name": displayName,
"warehouse_id": "{env.TEST_DEFAULT_WAREHOUSE_ID}",
Expand All @@ -310,7 +310,7 @@ func TestAccDashboardWithRemoteChange(t *testing.T) {
etag = dashboard.Etag
return nil
}),
}, step{
}, Step{
PreConfig: func() {
w, err := databricks.NewWorkspaceClient(&databricks.Config{})
require.NoError(t, err)
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestAccDashboardTestAll(t *testing.T) {
fileName := tmpDir + "/Dashboard.json"
var template templateStruct
displayName := fmt.Sprintf("Test Dashboard - %s", qa.RandomName())
workspaceLevel(t, step{
WorkspaceLevel(t, Step{
PreConfig: func() {
os.Mkdir(tmpDir, 0755)
os.WriteFile(fileName, []byte("{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page in file\"}]}"), 0644)
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestAccDashboardTestAll(t *testing.T) {
require.Equal(t, publish_dash.EmbedCredentials, false)
return nil
}),
}, step{
}, Step{
PreConfig: func() {
os.WriteFile(fileName, []byte("{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page Modified\"}]}"), 0644)
},
Expand All @@ -414,7 +414,7 @@ func TestAccDashboardTestAll(t *testing.T) {
assert.NotEqual(t, "", dashboard.SerializedDashboard)
return nil
}),
}, step{
}, Step{
PreConfig: func() {
w, err := databricks.NewWorkspaceClient(&databricks.Config{})
require.NoError(t, err)
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestAccDashboardTestAll(t *testing.T) {
require.NoError(t, err)
return nil
}),
}, step{
}, Step{
Template: makeTemplate(template.SetAttributes(map[string]string{
"embed_credentials": "true",
"parent_path": "/Shared/Teams",
Expand All @@ -466,7 +466,7 @@ func TestAccDashboardTestAll(t *testing.T) {
assert.NotEqual(t, "", dashboard.SerializedDashboard)
return nil
}),
}, step{
}, Step{
PreConfig: func() {
os.WriteFile(fileName, []byte("{\"pages\":[{\"name\":\"new_name\",\"displayName\":\"New Page Modified again\"}]}"), 0644)
},
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/data_aws_crossaccount_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestMwsAccDataSourceAwsCrossaccountPolicy(t *testing.T) {
GetEnvOrSkipTest(t, "TEST_ROOT_BUCKET") // marker for AWS test env
accountLevel(t, step{
AccountLevel(t, Step{
Template: `
data "databricks_aws_crossaccount_policy" "this" {
}`,
Expand Down
Loading

0 comments on commit bb871e1

Please sign in to comment.