@@ -235,6 +235,13 @@ func TestCatalogCreateCannotDeleteDefaultSchema(t *testing.T) {
235235func TestUpdateCatalog (t * testing.T ) {
236236 qa.ResourceFixture {
237237 Fixtures : []qa.HTTPFixture {
238+ {
239+ Method : "GET" ,
240+ Resource : "/api/2.1/unity-catalog/current-metastore-assignment" ,
241+ Response : catalog.MetastoreAssignment {
242+ MetastoreId : "d" ,
243+ },
244+ },
238245 {
239246 Method : "PATCH" ,
240247 Resource : "/api/2.1/unity-catalog/catalogs/a" ,
@@ -277,6 +284,144 @@ func TestUpdateCatalog(t *testing.T) {
277284 }.ApplyNoError (t )
278285}
279286
287+ func TestFailIfMetastoreIdIsWrong (t * testing.T ) {
288+ qa.ResourceFixture {
289+ Fixtures : []qa.HTTPFixture {
290+ {
291+ Method : "GET" ,
292+ Resource : "/api/2.1/unity-catalog/current-metastore-assignment" ,
293+ Response : catalog.MetastoreAssignment {
294+ MetastoreId : "old_id" ,
295+ },
296+ },
297+ },
298+ Resource : ResourceCatalog (),
299+ Update : true ,
300+ ID : "a" ,
301+ InstanceState : map [string ]string {
302+ "metastore_id" : "old_id" ,
303+ "name" : "a" ,
304+ "comment" : "c" ,
305+ },
306+ HCL : `
307+ metastore_id = "new_id"
308+ name = "a"
309+ comment = "c"
310+ owner = "administrators"
311+ ` ,
312+ }.ExpectError (t , "metastore_id must be empty or equal to the metastore id assigned to the workspace: old_id. " +
313+ "If the metastore assigned to the workspace has changed, the new metastore id must be explicitly set" )
314+ }
315+
316+ func TestUpdateCatalogIfMetastoreIdChanges (t * testing.T ) {
317+ qa.ResourceFixture {
318+ Fixtures : []qa.HTTPFixture {
319+ {
320+ Method : "GET" ,
321+ Resource : "/api/2.1/unity-catalog/current-metastore-assignment" ,
322+ Response : catalog.MetastoreAssignment {
323+ MetastoreId : "correct_id" ,
324+ },
325+ },
326+ {
327+ Method : "PATCH" ,
328+ Resource : "/api/2.1/unity-catalog/catalogs/a" ,
329+ ExpectedRequest : catalog.UpdateCatalog {
330+ Name : "a" ,
331+ Comment : "c" ,
332+ Owner : "administrators" ,
333+ },
334+ Response : catalog.CatalogInfo {
335+ Name : "a" ,
336+ MetastoreId : "correct_id" ,
337+ Comment : "c" ,
338+ Owner : "administrators" ,
339+ },
340+ },
341+ {
342+ Method : "GET" ,
343+ Resource : "/api/2.1/unity-catalog/catalogs/a?" ,
344+ Response : catalog.CatalogInfo {
345+ Name : "a" ,
346+ MetastoreId : "correct_id" ,
347+ Comment : "c" ,
348+ Owner : "administrators" ,
349+ },
350+ },
351+ },
352+ Resource : ResourceCatalog (),
353+ Update : true ,
354+ ID : "a" ,
355+ InstanceState : map [string ]string {
356+ "metastore_id" : "wrong_id" ,
357+ "name" : "a" ,
358+ "comment" : "c" ,
359+ },
360+ HCL : `
361+ metastore_id = "correct_id"
362+ name = "a"
363+ comment = "c"
364+ owner = "administrators"
365+ ` ,
366+ }.ApplyAndExpectData (t , map [string ]any {
367+ "metastore_id" : "correct_id" ,
368+ "name" : "a" ,
369+ "comment" : "c" ,
370+ })
371+ }
372+
373+ func TestUpdateCatalogIfMetastoreIdNotExplicitelySet (t * testing.T ) {
374+ qa.ResourceFixture {
375+ Fixtures : []qa.HTTPFixture {
376+ {
377+ Method : "GET" ,
378+ Resource : "/api/2.1/unity-catalog/current-metastore-assignment" ,
379+ Response : catalog.MetastoreAssignment {
380+ MetastoreId : "correct_id" ,
381+ },
382+ },
383+ {
384+ Method : "PATCH" ,
385+ Resource : "/api/2.1/unity-catalog/catalogs/a" ,
386+ ExpectedRequest : catalog.UpdateCatalog {
387+ Name : "a" ,
388+ Comment : "c" ,
389+ Owner : "administrators" ,
390+ },
391+ Response : catalog.CatalogInfo {
392+ Name : "a" ,
393+ MetastoreId : "correct_id" ,
394+ Comment : "c" ,
395+ Owner : "administrators" ,
396+ },
397+ },
398+ {
399+ Method : "GET" ,
400+ Resource : "/api/2.1/unity-catalog/catalogs/a?" ,
401+ Response : catalog.CatalogInfo {
402+ Name : "a" ,
403+ MetastoreId : "correct_id" ,
404+ Comment : "c" ,
405+ Owner : "administrators" ,
406+ },
407+ },
408+ },
409+ Resource : ResourceCatalog (),
410+ Update : true ,
411+ ID : "a" ,
412+ InstanceState : map [string ]string {
413+ "metastore_id" : "correct_id" ,
414+ "name" : "a" ,
415+ "comment" : "c" ,
416+ },
417+ HCL : `
418+ name = "a"
419+ comment = "c"
420+ owner = "administrators"
421+ ` ,
422+ }.ApplyNoError (t )
423+ }
424+
280425func TestForceDeleteCatalog (t * testing.T ) {
281426 qa.ResourceFixture {
282427 Fixtures : []qa.HTTPFixture {
0 commit comments