|
1 | 1 | package catalog |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "net/http" |
5 | 6 | "testing" |
6 | 7 |
|
| 8 | + "github.com/databricks/databricks-sdk-go/experimental/mocks" |
7 | 9 | "github.com/databricks/databricks-sdk-go/service/catalog" |
8 | 10 | "github.com/databricks/terraform-provider-databricks/common" |
9 | 11 | "github.com/databricks/terraform-provider-databricks/qa" |
10 | 12 | "github.com/stretchr/testify/assert" |
| 13 | + "github.com/stretchr/testify/mock" |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | func TestSystemSchemaCreate(t *testing.T) { |
@@ -87,6 +90,40 @@ func TestSystemSchemaCreate_Error(t *testing.T) { |
87 | 90 | assert.Equal(t, "", d.Id(), "Id should be empty for error creates") |
88 | 91 | } |
89 | 92 |
|
| 93 | +func TestSystemSchemaCreateAlreadyEnabled(t *testing.T) { |
| 94 | + qa.ResourceFixture{ |
| 95 | + MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { |
| 96 | + w.GetMockMetastoresAPI().EXPECT().Summary(mock.Anything).Return(&catalog.GetMetastoreSummaryResponse{ |
| 97 | + MetastoreId: "abc", |
| 98 | + }, nil) |
| 99 | + e := w.GetMockSystemSchemasAPI().EXPECT() |
| 100 | + e.Enable(mock.Anything, catalog.EnableRequest{ |
| 101 | + MetastoreId: "abc", |
| 102 | + SchemaName: "billing", |
| 103 | + }).Return(errors.New("billing system schema can only be enabled by Databricks")) |
| 104 | + e.ListByMetastoreId(mock.Anything, "abc").Return(&catalog.ListSystemSchemasResponse{ |
| 105 | + Schemas: []catalog.SystemSchemaInfo{ |
| 106 | + { |
| 107 | + Schema: "access", |
| 108 | + State: catalog.SystemSchemaInfoStateEnableCompleted, |
| 109 | + }, |
| 110 | + { |
| 111 | + Schema: "billing", |
| 112 | + State: catalog.SystemSchemaInfoStateEnableCompleted, |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, nil) |
| 116 | + }, |
| 117 | + Resource: ResourceSystemSchema(), |
| 118 | + HCL: `schema = "billing"`, |
| 119 | + Create: true, |
| 120 | + }.ApplyAndExpectData(t, map[string]any{ |
| 121 | + "schema": "billing", |
| 122 | + "id": "abc|billing", |
| 123 | + "full_name": "system.billing", |
| 124 | + }) |
| 125 | +} |
| 126 | + |
90 | 127 | func TestSystemSchemaUpdate(t *testing.T) { |
91 | 128 | d, err := qa.ResourceFixture{ |
92 | 129 | Fixtures: []qa.HTTPFixture{ |
|
0 commit comments