Skip to content

Commit 66d718c

Browse files
authored
Added acceptant tests for databricks_schemas data source (#2074)
1 parent 0693e4c commit 66d718c

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

catalog/data_schemas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func DataSourceSchemas() *schema.Resource {
1919
return err
2020
}
2121
for _, v := range schemas {
22-
data.Ids = append(data.Ids, v.Name)
22+
data.Ids = append(data.Ids, v.FullName)
2323
}
2424
return nil
2525
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)