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