Skip to content

Commit c99f9d8

Browse files
authored
[Internal] Enable SQL tables Acc tests on GCP and optimize usage (#4528)
## Changes <!-- Summary of your changes that are easy to understand --> - Tests for `databricks_sql_table` were disabled on GCP, so re-enable them. - Wwitched to use default SQL warehouse to speedup tests. - Switched from `databricks_table` in acceptance test for `databricks_tables` data source. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework NO_CHANGELOG=true
1 parent 5346452 commit c99f9d8

File tree

4 files changed

+31
-100
lines changed

4 files changed

+31
-100
lines changed

catalog/data_table_acc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestUcAccDataSourceTable(t *testing.T) {
4141
name = "bar"
4242
table_type = "MANAGED"
4343
data_source_format = "DELTA"
44+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
4445
4546
column {
4647
name = "id"

catalog/data_tables_acc_test.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func checkTablesDataSourcePopulated(t *testing.T) func(s *terraform.State) error
1717

1818
attr := r.Primary.Attributes
1919

20-
assert.Equal(t, s.Modules[0].Resources["databricks_table.mytable"].Primary.ID, attr["ids.0"])
21-
assert.Equal(t, s.Modules[0].Resources["databricks_table.mytable_2"].Primary.ID, attr["ids.1"])
20+
assert.Equal(t, s.Modules[0].Resources["databricks_sql_table.mytable"].Primary.ID, attr["ids.0"])
21+
assert.Equal(t, s.Modules[0].Resources["databricks_sql_table.mytable_2"].Primary.ID, attr["ids.1"])
2222

2323
num_tables, _ := strconv.Atoi(s.Modules[0].Outputs["tables"].Value.(string))
2424
assert.Equal(t, num_tables, 2)
@@ -45,44 +45,40 @@ func TestUcAccDataSourceTables(t *testing.T) {
4545
}
4646
}
4747
48-
resource "databricks_table" "mytable" {
48+
resource "databricks_sql_table" "mytable" {
4949
catalog_name = databricks_catalog.sandbox.id
5050
schema_name = databricks_schema.things.name
5151
name = "bar"
5252
table_type = "MANAGED"
5353
data_source_format = "DELTA"
54+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
5455
5556
column {
56-
name = "id"
57-
position = 0
58-
type_name = "INT"
59-
type_text = "int"
60-
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}"
57+
name = "id"
58+
type = "int"
6159
}
6260
}
6361
64-
resource "databricks_table" "mytable_2" {
62+
resource "databricks_sql_table" "mytable_2" {
6563
catalog_name = databricks_catalog.sandbox.id
6664
schema_name = databricks_schema.things.name
6765
name = "bar_2"
6866
table_type = "MANAGED"
6967
data_source_format = "DELTA"
68+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
7069
7170
column {
72-
name = "id"
73-
position = 0
74-
type_name = "INT"
75-
type_text = "int"
76-
type_json = "{\"name\":\"id\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}"
71+
name = "id"
72+
type = "int"
7773
}
7874
}
7975
8076
data "databricks_tables" "this" {
8177
catalog_name = databricks_catalog.sandbox.id
8278
schema_name = databricks_schema.things.name
8379
depends_on = [
84-
databricks_table.mytable,
85-
databricks_table.mytable_2
80+
databricks_sql_table.mytable,
81+
databricks_sql_table.mytable_2
8682
]
8783
}
8884
output "tables" {

catalog/online_table_test.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,13 @@ resource "databricks_catalog" "sandbox" {
2727
force_destroy = true
2828
}
2929
30-
resource "databricks_sql_endpoint" "this" {
31-
name = "tf-{var.STICKY_RANDOM}"
32-
cluster_size = "2X-Small"
33-
max_num_clusters = 1
34-
warehouse_type = "PRO"
35-
tags {
36-
custom_tags {
37-
key = "Owner"
38-
value = "eng-dev-ecosystem-team_at_databricks.com"
39-
}
40-
}
41-
}
42-
43-
resource "databricks_sql_table" "table" {
30+
resource "databricks_sql_table" "table" {
4431
catalog_name = databricks_catalog.sandbox.id
4532
schema_name = databricks_schema.things.name
4633
name = "ot_src_{var.STICKY_RANDOM}"
4734
table_type = "MANAGED"
4835
data_source_format = "DELTA"
49-
warehouse_id = databricks_sql_endpoint.this.id
36+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
5037
5138
column {
5239
name = "id"

sql/sql_table_test.go

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sql_test
22

33
import (
44
"fmt"
5-
"os"
65
"regexp"
76
"strconv"
87
"testing"
@@ -12,9 +11,6 @@ import (
1211
)
1312

1413
func TestUcAccResourceSqlTable_Managed(t *testing.T) {
15-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
16-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
17-
}
1814
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
1915
Template: `
2016
resource "databricks_schema" "this" {
@@ -27,6 +23,7 @@ func TestUcAccResourceSqlTable_Managed(t *testing.T) {
2723
catalog_name = "main"
2824
schema_name = databricks_schema.this.name
2925
table_type = "MANAGED"
26+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
3027
properties = {
3128
this = "that"
3229
something = "else"
@@ -55,6 +52,7 @@ func TestUcAccResourceSqlTable_Managed(t *testing.T) {
5552
catalog_name = "main"
5653
schema_name = databricks_schema.this.name
5754
table_type = "MANAGED"
55+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
5856
properties = {
5957
that = "this"
6058
something = "else2"
@@ -74,9 +72,6 @@ func TestUcAccResourceSqlTable_Managed(t *testing.T) {
7472
}
7573

7674
func TestUcAccResourceSqlTableWithIdentityColumn_Managed(t *testing.T) {
77-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
78-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
79-
}
8075
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
8176
Template: `
8277
resource "databricks_schema" "this" {
@@ -89,6 +84,7 @@ func TestUcAccResourceSqlTableWithIdentityColumn_Managed(t *testing.T) {
8984
catalog_name = "main"
9085
schema_name = databricks_schema.this.name
9186
table_type = "MANAGED"
87+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
9288
properties = {
9389
this = "that"
9490
something = "else"
@@ -118,6 +114,7 @@ func TestUcAccResourceSqlTableWithIdentityColumn_Managed(t *testing.T) {
118114
catalog_name = "main"
119115
schema_name = databricks_schema.this.name
120116
table_type = "MANAGED"
117+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
121118
properties = {
122119
that = "this"
123120
something = "else2"
@@ -167,17 +164,19 @@ func TestUcAccResourceSqlTable_External(t *testing.T) {
167164
schema_name = databricks_schema.this.name
168165
table_type = "EXTERNAL"
169166
data_source_format = "DELTA"
170-
storage_location = "s3://{env.TEST_BUCKET}/some{var.RANDOM}"
167+
storage_location = databricks_external_location.some.url
171168
comment = "this table is managed by terraform"
172169
owner = "account users"
170+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
171+
172+
depends_on = [
173+
databricks_external_location.some
174+
]
173175
}`,
174176
})
175177
}
176178

177179
func TestUcAccResourceSqlTable_View(t *testing.T) {
178-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
179-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
180-
}
181180
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
182181
Template: `
183182
resource "databricks_schema" "this" {
@@ -193,6 +192,7 @@ func TestUcAccResourceSqlTable_View(t *testing.T) {
193192
data_source_format = "DELTA"
194193
comment = "this table is managed by terraform..."
195194
owner = "account users"
195+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
196196
197197
column {
198198
name = "id"
@@ -212,6 +212,7 @@ func TestUcAccResourceSqlTable_View(t *testing.T) {
212212
table_type = "VIEW"
213213
comment = "this view is managed by terraform..."
214214
view_definition = format("SELECT id, name FROM %s", databricks_sql_table.this.id)
215+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
215216
216217
column {
217218
name = "id"
@@ -226,24 +227,8 @@ func TestUcAccResourceSqlTable_View(t *testing.T) {
226227
}
227228

228229
func TestUcAccResourceSqlTable_WarehousePartition(t *testing.T) {
229-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
230-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
231-
}
232230
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
233231
Template: `
234-
resource "databricks_sql_endpoint" "this" {
235-
name = "tf-{var.RANDOM}"
236-
cluster_size = "2X-Small"
237-
max_num_clusters = 1
238-
239-
tags {
240-
custom_tags {
241-
key = "Owner"
242-
243-
}
244-
}
245-
}
246-
247232
resource "databricks_schema" "this" {
248233
name = "{var.STICKY_RANDOM}"
249234
catalog_name = "main"
@@ -254,7 +239,7 @@ func TestUcAccResourceSqlTable_WarehousePartition(t *testing.T) {
254239
catalog_name = "main"
255240
schema_name = databricks_schema.this.name
256241
table_type = "MANAGED"
257-
warehouse_id = databricks_sql_endpoint.this.id
242+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
258243
properties = {
259244
them = "that"
260245
something = "else"
@@ -277,9 +262,6 @@ func TestUcAccResourceSqlTable_WarehousePartition(t *testing.T) {
277262
})
278263
}
279264
func TestUcAccResourceSqlTable_Liquid(t *testing.T) {
280-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
281-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
282-
}
283265
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
284266
Template: `
285267
resource "databricks_schema" "this" {
@@ -292,6 +274,7 @@ func TestUcAccResourceSqlTable_Liquid(t *testing.T) {
292274
catalog_name = "main"
293275
schema_name = databricks_schema.this.name
294276
table_type = "MANAGED"
277+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
295278
properties = {
296279
them = "that"
297280
something = "else"
@@ -323,6 +306,7 @@ func TestUcAccResourceSqlTable_Liquid(t *testing.T) {
323306
catalog_name = "main"
324307
schema_name = databricks_schema.this.name
325308
table_type = "MANAGED"
309+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
326310
properties = {
327311
them = "that"
328312
something = "else"
@@ -359,6 +343,7 @@ func constructManagedSqlTableTemplate(tableName string, columnInfos []catalog.Sq
359343
catalog_name = "main"
360344
schema_name = databricks_schema.this.name
361345
table_type = "MANAGED"
346+
warehouse_id = "{env.TEST_DEFAULT_WAREHOUSE_ID}"
362347
properties = {
363348
"this" = "that"
364349
"something" = "else"
@@ -381,9 +366,6 @@ var inlineAndMembershipChangeErrorPattern = "detected changes in both number of
381366
var inlineAndMembershipChangeErrorRegex = regexp.MustCompile(inlineAndMembershipChangeErrorPattern)
382367

383368
func TestUcAccResourceSqlTable_RenameColumn(t *testing.T) {
384-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
385-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
386-
}
387369
tableName := acceptance.RandomName()
388370
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
389371
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -406,9 +388,6 @@ func constructManagedSqlTableTemplateWithColumnTypeUpdates(tableName string, col
406388
}
407389

408390
func TestUcAccResourceSqlTable_ColumnTypeSuppressDiff(t *testing.T) {
409-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
410-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
411-
}
412391
tableName := acceptance.RandomName()
413392
columnName := acceptance.RandomName()
414393
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
@@ -448,9 +427,6 @@ func TestUcAccResourceSqlTable_ColumnTypeSuppressDiff(t *testing.T) {
448427
}
449428

450429
func TestUcAccResourceSqlTable_AddColumnComment(t *testing.T) {
451-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
452-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
453-
}
454430
tableName := acceptance.RandomName()
455431
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
456432
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -460,9 +436,6 @@ func TestUcAccResourceSqlTable_AddColumnComment(t *testing.T) {
460436
}
461437

462438
func TestUcAccResourceSqlTable_DropColumnNullable(t *testing.T) {
463-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
464-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
465-
}
466439
tableName := acceptance.RandomName()
467440
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
468441
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -472,9 +445,6 @@ func TestUcAccResourceSqlTable_DropColumnNullable(t *testing.T) {
472445
}
473446

474447
func TestUcAccResourceSqlTable_MultipleColumnUpdates(t *testing.T) {
475-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
476-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
477-
}
478448
tableName := acceptance.RandomName()
479449
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
480450
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -484,9 +454,6 @@ func TestUcAccResourceSqlTable_MultipleColumnUpdates(t *testing.T) {
484454
}
485455

486456
func TestUcAccResourceSqlTable_ChangeColumnTypeThrows(t *testing.T) {
487-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
488-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
489-
}
490457
tableName := acceptance.RandomName()
491458

492459
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
@@ -498,9 +465,6 @@ func TestUcAccResourceSqlTable_ChangeColumnTypeThrows(t *testing.T) {
498465
}
499466

500467
func TestUcAccResourceSqlTable_DropColumn(t *testing.T) {
501-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
502-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
503-
}
504468
tableName := acceptance.RandomName()
505469
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
506470
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{
@@ -513,9 +477,6 @@ func TestUcAccResourceSqlTable_DropColumn(t *testing.T) {
513477
}
514478

515479
func TestUcAccResourceSqlTable_DropMultipleColumns(t *testing.T) {
516-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
517-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
518-
}
519480
tableName := acceptance.RandomName()
520481
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
521482
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{
@@ -529,9 +490,6 @@ func TestUcAccResourceSqlTable_DropMultipleColumns(t *testing.T) {
529490
}
530491

531492
func TestUcAccResourceSqlTable_AddColumn(t *testing.T) {
532-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
533-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
534-
}
535493
tableName := acceptance.RandomName()
536494
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
537495
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -544,9 +502,6 @@ func TestUcAccResourceSqlTable_AddColumn(t *testing.T) {
544502
}
545503

546504
func TestUcAccResourceSqlTable_AddMultipleColumns(t *testing.T) {
547-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
548-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
549-
}
550505
tableName := acceptance.RandomName()
551506
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
552507
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -560,10 +515,6 @@ func TestUcAccResourceSqlTable_AddMultipleColumns(t *testing.T) {
560515
}
561516

562517
func TestUcAccResourceSqlTable_AddColumnAndUpdateThrows(t *testing.T) {
563-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
564-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
565-
}
566-
567518
tableName := acceptance.RandomName()
568519
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
569520
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "string", Nullable: true, Comment: "comment"}}),
@@ -577,10 +528,6 @@ func TestUcAccResourceSqlTable_AddColumnAndUpdateThrows(t *testing.T) {
577528
}
578529

579530
func TestUcAccResourceSqlTable_DropColumnAndUpdateThrows(t *testing.T) {
580-
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
581-
acceptance.Skipf(t)("databricks_sql_table resource not available on GCP")
582-
}
583-
584531
tableName := acceptance.RandomName()
585532
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
586533
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{

0 commit comments

Comments
 (0)