Skip to content

Commit

Permalink
Replace custom contains function
Browse files Browse the repository at this point in the history
  • Loading branch information
ehab-eb committed Dec 5, 2023
1 parent a7392f5 commit fce534f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
3 changes: 2 additions & 1 deletion catalog/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"golang.org/x/exp/slices"
)

func updateFunctionFactory(pathPrefix string, updatable []string) func(context.Context, *schema.ResourceData, *common.DatabricksClient) error {
Expand All @@ -14,7 +15,7 @@ func updateFunctionFactory(pathPrefix string, updatable []string) func(context.C
for _, field := range updatable {

// these fields cannot be set during creation
if d.IsNewResource() && !common.Contains([]string{
if d.IsNewResource() && !slices.Contains([]string{
"owner",
"delta_sharing_scope",
"delta_sharing_recipient_token_lifetime_in_seconds",
Expand Down
9 changes: 0 additions & 9 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ var (
func StringIsUUID(s string) bool {
return uuidRegex.MatchString(s)
}

func Contains[T comparable](s []T, e T) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
7 changes: 0 additions & 7 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,3 @@ func TestStringIsUUID(t *testing.T) {
assert.True(t, StringIsUUID("3f670caf-9a4b-4479-8143-1a0878da8f57"))
assert.False(t, StringIsUUID("abc"))
}

func TestContains(t *testing.T) {
assert.True(t, Contains[string]([]string{"a", "b", "c"}, "a"))
assert.False(t, Contains[string]([]string{"a", "b", "c"}, "d"))
assert.True(t, Contains[int]([]int{1, 2, 3}, 1))
assert.False(t, Contains[int]([]int{1, 2, 3}, 4))
}

0 comments on commit fce534f

Please sign in to comment.