Skip to content

Commit 17000a5

Browse files
tanmay-dbalexott
andauthored
[Internal] Catalog tests cleanup to use plan checks (#5112)
## Changes <!-- Summary of your changes that are easy to understand --> We use the internal library to checking planned actions. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> Integration test --------- Co-authored-by: Alex Ott <[email protected]>
1 parent 03228c7 commit 17000a5

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
### Exporter
1919

2020
### Internal Changes
21+
* Refactor `catalog_test.go` to use internal plan checks ([#5112](https://github.com/databricks/terraform-provider-databricks/pull/5112)).

catalog/catalog_test.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package catalog_test
22

33
import (
4-
"context"
54
"fmt"
65
"regexp"
7-
"strings"
86
"testing"
97

108
"github.com/databricks/terraform-provider-databricks/internal/acceptance"
119
"github.com/databricks/terraform-provider-databricks/qa"
12-
tfjson "github.com/hashicorp/terraform-json"
1310
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1411
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1512
)
@@ -62,35 +59,6 @@ func TestUcAccCatalogIsolated(t *testing.T) {
6259
})
6360
}
6461

65-
type checkResourceRecreate struct {
66-
address string
67-
}
68-
69-
func (c checkResourceRecreate) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp *plancheck.CheckPlanResponse) {
70-
var change *tfjson.ResourceChange
71-
for _, resourceChange := range req.Plan.ResourceChanges {
72-
if resourceChange.Address == c.address {
73-
change = resourceChange
74-
break
75-
}
76-
}
77-
if change == nil {
78-
addressesWithPlannedChanges := make([]string, 0, len(req.Plan.ResourceChanges))
79-
for _, change := range req.Plan.ResourceChanges {
80-
addressesWithPlannedChanges = append(addressesWithPlannedChanges, change.Address)
81-
}
82-
resp.Error = fmt.Errorf("address %s not found in resource changes; only planned changes for addresses %s", c.address, strings.Join(addressesWithPlannedChanges, ", "))
83-
return
84-
}
85-
if change.Change.Actions[0] != tfjson.ActionDelete {
86-
plannedActions := make([]string, 0, len(change.Change.Actions))
87-
for _, action := range change.Change.Actions {
88-
plannedActions = append(plannedActions, string(action))
89-
}
90-
resp.Error = fmt.Errorf("no delete is planned for %s; planned actions are: %s", c.address, strings.Join(plannedActions, ", "))
91-
}
92-
}
93-
9462
func TestUcAccCatalogUpdate(t *testing.T) {
9563
acceptance.LoadUcwsEnv(t)
9664
acceptance.UnityWorkspaceLevel(t, acceptance.Step{
@@ -153,7 +121,7 @@ func TestUcAccCatalogUpdate(t *testing.T) {
153121
}`, getPredictiveOptimizationSetting(t, false)),
154122
ConfigPlanChecks: resource.ConfigPlanChecks{
155123
PreApply: []plancheck.PlanCheck{
156-
checkResourceRecreate{address: "databricks_catalog.sandbox"},
124+
plancheck.ExpectResourceAction("databricks_catalog.sandbox", plancheck.ResourceActionDestroyBeforeCreate),
157125
},
158126
},
159127
})

0 commit comments

Comments
 (0)