|
| 1 | +package catalog |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/databricks/databricks-sdk-go/apierr" |
| 8 | + "github.com/databricks/databricks-sdk-go/service/catalog" |
| 9 | + "github.com/databricks/terraform-provider-databricks/qa" |
| 10 | +) |
| 11 | + |
| 12 | +func TestRegisteredModelCornerCases(t *testing.T) { |
| 13 | + qa.ResourceCornerCases(t, ResourceRegisteredModel()) |
| 14 | +} |
| 15 | + |
| 16 | +func TestRegisteredModelCreate(t *testing.T) { |
| 17 | + qa.ResourceFixture{ |
| 18 | + Fixtures: []qa.HTTPFixture{ |
| 19 | + { |
| 20 | + Method: http.MethodPost, |
| 21 | + Resource: "/api/2.1/unity-catalog/models", |
| 22 | + ExpectedRequest: catalog.CreateRegisteredModelRequest{ |
| 23 | + Name: "model", |
| 24 | + CatalogName: "catalog", |
| 25 | + SchemaName: "schema", |
| 26 | + Comment: "comment", |
| 27 | + }, |
| 28 | + Response: catalog.RegisteredModelInfo{ |
| 29 | + Name: "model", |
| 30 | + CatalogName: "catalog", |
| 31 | + SchemaName: "schema", |
| 32 | + FullName: "catalog.schema.model", |
| 33 | + Comment: "comment", |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + Method: http.MethodGet, |
| 38 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 39 | + Response: catalog.RegisteredModelInfo{ |
| 40 | + Name: "model", |
| 41 | + CatalogName: "catalog", |
| 42 | + SchemaName: "schema", |
| 43 | + FullName: "catalog.schema.model", |
| 44 | + Comment: "comment", |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + Resource: ResourceRegisteredModel(), |
| 49 | + HCL: ` |
| 50 | + name = "model" |
| 51 | + catalog_name = "catalog" |
| 52 | + schema_name = "schema" |
| 53 | + comment = "comment" |
| 54 | + `, |
| 55 | + Create: true, |
| 56 | + }.ApplyAndExpectData(t, |
| 57 | + map[string]any{ |
| 58 | + "id": "catalog.schema.model", |
| 59 | + }, |
| 60 | + ) |
| 61 | +} |
| 62 | + |
| 63 | +func TestRegisteredModelCreate_Error(t *testing.T) { |
| 64 | + qa.ResourceFixture{ |
| 65 | + Fixtures: []qa.HTTPFixture{ |
| 66 | + { |
| 67 | + Method: http.MethodPost, |
| 68 | + Resource: "/api/2.1/unity-catalog/models", |
| 69 | + Response: apierr.APIErrorBody{ |
| 70 | + ErrorCode: "INVALID_REQUEST", |
| 71 | + Message: "Internal error happened", |
| 72 | + }, |
| 73 | + Status: 400, |
| 74 | + }, |
| 75 | + }, |
| 76 | + Resource: ResourceRegisteredModel(), |
| 77 | + Create: true, |
| 78 | + }.ExpectError(t, "Internal error happened") |
| 79 | +} |
| 80 | + |
| 81 | +func TestRegisteredModelRead(t *testing.T) { |
| 82 | + qa.ResourceFixture{ |
| 83 | + Fixtures: []qa.HTTPFixture{ |
| 84 | + { |
| 85 | + Method: http.MethodGet, |
| 86 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 87 | + Response: catalog.RegisteredModelInfo{ |
| 88 | + Name: "model", |
| 89 | + CatalogName: "catalog", |
| 90 | + SchemaName: "schema", |
| 91 | + FullName: "catalog.schema.model", |
| 92 | + Comment: "comment", |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + Resource: ResourceRegisteredModel(), |
| 97 | + Read: true, |
| 98 | + ID: "catalog.schema.model", |
| 99 | + }.ApplyAndExpectData(t, |
| 100 | + map[string]any{ |
| 101 | + "id": "catalog.schema.model", |
| 102 | + }, |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +func TestRegisteredModelRead_Error(t *testing.T) { |
| 107 | + qa.ResourceFixture{ |
| 108 | + Fixtures: []qa.HTTPFixture{ |
| 109 | + { |
| 110 | + Method: http.MethodGet, |
| 111 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 112 | + Response: apierr.APIErrorBody{ |
| 113 | + ErrorCode: "INVALID_REQUEST", |
| 114 | + Message: "Internal error happened", |
| 115 | + }, |
| 116 | + Status: 400, |
| 117 | + }, |
| 118 | + }, |
| 119 | + Resource: ResourceRegisteredModel(), |
| 120 | + Read: true, |
| 121 | + ID: "catalog.schema.model", |
| 122 | + }.ExpectError(t, "Internal error happened") |
| 123 | +} |
| 124 | + |
| 125 | +func TestRegisteredModelUpdate(t *testing.T) { |
| 126 | + qa.ResourceFixture{ |
| 127 | + Fixtures: []qa.HTTPFixture{ |
| 128 | + { |
| 129 | + Method: http.MethodPatch, |
| 130 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model", |
| 131 | + ExpectedRequest: catalog.UpdateRegisteredModelRequest{ |
| 132 | + FullName: "catalog.schema.model", |
| 133 | + Comment: "new comment", |
| 134 | + Name: "model", |
| 135 | + }, |
| 136 | + Response: catalog.RegisteredModelInfo{ |
| 137 | + Name: "model", |
| 138 | + CatalogName: "catalog", |
| 139 | + SchemaName: "schema", |
| 140 | + FullName: "catalog.schema.model", |
| 141 | + Comment: "new comment", |
| 142 | + }, |
| 143 | + }, |
| 144 | + { |
| 145 | + Method: http.MethodGet, |
| 146 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 147 | + Response: catalog.RegisteredModelInfo{ |
| 148 | + Name: "model", |
| 149 | + CatalogName: "catalog", |
| 150 | + SchemaName: "schema", |
| 151 | + FullName: "catalog.schema.model", |
| 152 | + Comment: "new comment", |
| 153 | + }, |
| 154 | + }, |
| 155 | + }, |
| 156 | + Resource: ResourceRegisteredModel(), |
| 157 | + Update: true, |
| 158 | + ID: "catalog.schema.model", |
| 159 | + InstanceState: map[string]string{ |
| 160 | + "name": "model", |
| 161 | + "catalog_name": "catalog", |
| 162 | + "schema_name": "schema", |
| 163 | + "comment": "comment", |
| 164 | + }, |
| 165 | + HCL: ` |
| 166 | + name = "model" |
| 167 | + catalog_name = "catalog" |
| 168 | + schema_name = "schema" |
| 169 | + comment = "new comment" |
| 170 | + `, |
| 171 | + }.ApplyNoError(t) |
| 172 | +} |
| 173 | + |
| 174 | +func TestRegisteredModelUpdate_Error(t *testing.T) { |
| 175 | + qa.ResourceFixture{ |
| 176 | + Fixtures: []qa.HTTPFixture{ |
| 177 | + { |
| 178 | + Method: http.MethodPatch, |
| 179 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model", |
| 180 | + Response: apierr.APIErrorBody{ |
| 181 | + ErrorCode: "INVALID_REQUEST", |
| 182 | + Message: "Internal error happened", |
| 183 | + }, |
| 184 | + Status: 400, |
| 185 | + }, |
| 186 | + }, |
| 187 | + Resource: ResourceRegisteredModel(), |
| 188 | + Update: true, |
| 189 | + ID: "catalog.schema.model", |
| 190 | + InstanceState: map[string]string{ |
| 191 | + "name": "model", |
| 192 | + "catalog_name": "catalog", |
| 193 | + "schema_name": "schema", |
| 194 | + "comment": "comment", |
| 195 | + }, |
| 196 | + HCL: ` |
| 197 | + name = "model" |
| 198 | + catalog_name = "catalog" |
| 199 | + schema_name = "schema" |
| 200 | + comment = "new comment" |
| 201 | + `, |
| 202 | + }.ExpectError(t, "Internal error happened") |
| 203 | +} |
| 204 | + |
| 205 | +func TestRegisteredModelDelete(t *testing.T) { |
| 206 | + qa.ResourceFixture{ |
| 207 | + Fixtures: []qa.HTTPFixture{ |
| 208 | + { |
| 209 | + Method: http.MethodDelete, |
| 210 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 211 | + Response: "", |
| 212 | + }, |
| 213 | + }, |
| 214 | + Resource: ResourceRegisteredModel(), |
| 215 | + Delete: true, |
| 216 | + ID: "catalog.schema.model", |
| 217 | + }.ApplyNoError(t) |
| 218 | +} |
| 219 | + |
| 220 | +func TestRegisteredModelDelete_Error(t *testing.T) { |
| 221 | + qa.ResourceFixture{ |
| 222 | + Fixtures: []qa.HTTPFixture{ |
| 223 | + { |
| 224 | + Method: http.MethodDelete, |
| 225 | + Resource: "/api/2.1/unity-catalog/models/catalog.schema.model?", |
| 226 | + Response: apierr.APIErrorBody{ |
| 227 | + ErrorCode: "INVALID_REQUEST", |
| 228 | + Message: "Internal error happened", |
| 229 | + }, |
| 230 | + Status: 400, |
| 231 | + }, |
| 232 | + }, |
| 233 | + Resource: ResourceRegisteredModel(), |
| 234 | + Delete: true, |
| 235 | + ID: "catalog.schema.model", |
| 236 | + }.ExpectError(t, "Internal error happened") |
| 237 | +} |
0 commit comments