Skip to content

Commit

Permalink
[Internal] Move volumes test next to plugin framework data source (#3995
Browse files Browse the repository at this point in the history
)

## Changes
<!-- Summary of your changes that are easy to understand -->
- Moving the test file to be next to the data source 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 bb871e1 commit 0cb0c8a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 48 deletions.
48 changes: 0 additions & 48 deletions internal/acceptance/data_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,51 +58,3 @@ func TestUcAccDataSourceVolumes(t *testing.T) {
Check: checkDataSourceVolumesPopulated(t),
})
}

func checkDataSourceVolumesPluginFrameworkPopulated(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
_, ok := s.Modules[0].Resources["data.databricks_volumes_pluginframework.this"]
require.True(t, ok, "data.databricks_volumes_pluginframework.this has to be there")
num_volumes, _ := strconv.Atoi(s.Modules[0].Outputs["volumes"].Value.(string))
assert.GreaterOrEqual(t, num_volumes, 1)
return nil
}
}

func TestUcAccDataSourceVolumesPluginFramework(t *testing.T) {
UnityWorkspaceLevel(t, Step{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.RANDOM}"
comment = "this catalog is managed by terraform"
properties = {
purpose = "testing"
}
}
resource "databricks_schema" "things" {
catalog_name = databricks_catalog.sandbox.id
name = "things{var.RANDOM}"
comment = "this database is managed by terraform"
properties = {
kind = "various"
}
}
resource "databricks_volume" "this" {
name = "volume_data_source_test"
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.things.name
volume_type = "MANAGED"
}
data "databricks_volumes_pluginframework" "this" {
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.things.name
depends_on = [ databricks_volume.this ]
}
output "volumes" {
value = length(data.databricks_volumes_pluginframework.this.ids)
}
`,
Check: checkDataSourceVolumesPluginFrameworkPopulated(t),
})
}
59 changes: 59 additions & 0 deletions internal/providers/pluginfw/resources/volume/data_volumes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package volume_test

import (
"strconv"
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func checkDataSourceVolumesPluginFrameworkPopulated(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
_, ok := s.Modules[0].Resources["data.databricks_volumes_pluginframework.this"]
require.True(t, ok, "data.databricks_volumes_pluginframework.this has to be there")
num_volumes, _ := strconv.Atoi(s.Modules[0].Outputs["volumes"].Value.(string))
assert.GreaterOrEqual(t, num_volumes, 1)
return nil
}
}

func TestUcAccDataSourceVolumesPluginFramework(t *testing.T) {
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
Template: `
resource "databricks_catalog" "sandbox" {
name = "sandbox{var.RANDOM}"
comment = "this catalog is managed by terraform"
properties = {
purpose = "testing"
}
}
resource "databricks_schema" "things" {
catalog_name = databricks_catalog.sandbox.id
name = "things{var.RANDOM}"
comment = "this database is managed by terraform"
properties = {
kind = "various"
}
}
resource "databricks_volume" "this" {
name = "volume_data_source_test"
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.things.name
volume_type = "MANAGED"
}
data "databricks_volumes_pluginframework" "this" {
catalog_name = databricks_catalog.sandbox.name
schema_name = databricks_schema.things.name
depends_on = [ databricks_volume.this ]
}
output "volumes" {
value = length(data.databricks_volumes_pluginframework.this.ids)
}
`,
Check: checkDataSourceVolumesPluginFrameworkPopulated(t),
})
}

0 comments on commit 0cb0c8a

Please sign in to comment.