|
| 1 | +package acceptance |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 8 | + "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func checkDataSourceVolumesPopulated(t *testing.T) func(s *terraform.State) error { |
| 13 | + return func(s *terraform.State) error { |
| 14 | + _, ok := s.Modules[0].Resources["data.databricks_volumes.this"] |
| 15 | + require.True(t, ok, "data.databricks_volumes.this has to be there") |
| 16 | + num_volumes, _ := strconv.Atoi(s.Modules[0].Outputs["volumes"].Value.(string)) |
| 17 | + assert.GreaterOrEqual(t, num_volumes, 1) |
| 18 | + return nil |
| 19 | + } |
| 20 | +} |
| 21 | +func TestUcAccDataSourceVolumes(t *testing.T) { |
| 22 | + unityWorkspaceLevel(t, step{ |
| 23 | + Template: ` |
| 24 | + resource "databricks_catalog" "sandbox" { |
| 25 | + name = "sandbox{var.RANDOM}" |
| 26 | + comment = "this catalog is managed by terraform" |
| 27 | + properties = { |
| 28 | + purpose = "testing" |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + resource "databricks_schema" "things" { |
| 33 | + catalog_name = databricks_catalog.sandbox.id |
| 34 | + name = "things{var.RANDOM}" |
| 35 | + comment = "this database is managed by terraform" |
| 36 | + properties = { |
| 37 | + kind = "various" |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + resource "databricks_volume" "this" { |
| 42 | + name = "volume_data_source_test" |
| 43 | + catalog_name = databricks_catalog.sandbox.name |
| 44 | + schema_name = databricks_schema.things.name |
| 45 | + volume_type = "MANAGED" |
| 46 | + } |
| 47 | +
|
| 48 | + data "databricks_volumes" "this" { |
| 49 | + catalog_name = databricks_catalog.sandbox.name |
| 50 | + schema_name = databricks_schema.things.name |
| 51 | + depends_on = [ databricks_volume.this ] |
| 52 | + } |
| 53 | +
|
| 54 | + output "volumes" { |
| 55 | + value = length(data.databricks_volumes.this.ids) |
| 56 | + } |
| 57 | + `, |
| 58 | + Check: checkDataSourceVolumesPopulated(t), |
| 59 | + }) |
| 60 | +} |
0 commit comments