Skip to content

Commit

Permalink
Review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Sep 17, 2024
1 parent 54f0be7 commit c4cf1a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/resources/diff_suppressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func suppressIdentifierQuoting(_, oldValue, newValue string, _ *schema.ResourceD
return slices.Equal(oldId, newId)
}

// IgnoreNewEmptyList suppresses the diff if `new` list is empty or compared subfield is ignored
func IgnoreNewEmptyList(subfields []string) schema.SchemaDiffSuppressFunc {
// IgnoreNewEmptyListOrSubfields suppresses the diff if `new` list is empty or compared subfield is ignored. Subfields can be nested.
func IgnoreNewEmptyListOrSubfields(ignoredSubfields ...string) schema.SchemaDiffSuppressFunc {
return func(k, old, new string, _ *schema.ResourceData) bool {
parts := strings.SplitN(k, ".", 3)
if len(parts) < 2 {
Expand All @@ -235,6 +235,6 @@ func IgnoreNewEmptyList(subfields []string) schema.SchemaDiffSuppressFunc {
return true
}
// key is one of the ignored subfields
return len(parts) > 2 && slices.Contains(subfields, parts[2]) && new == ""
return len(parts) == 3 && slices.Contains(ignoredSubfields, parts[2]) && new == ""
}
}
2 changes: 1 addition & 1 deletion pkg/resources/diff_suppressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func Test_ignoreNewEmptyList(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.suppress, resources.IgnoreNewEmptyList(tt.subfields)(tt.key, tt.old, tt.new, nil))
require.Equal(t, tt.suppress, resources.IgnoreNewEmptyListOrSubfields(tt.subfields...)(tt.key, tt.old, tt.new, nil))
})
}
}
2 changes: 1 addition & 1 deletion pkg/resources/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var viewSchema = map[string]*schema.Schema{
},
},
Description: "If you want to change the name of a column or add a comment to a column in the new view, include a column list that specifies the column names and (if needed) comments about the columns. You do not need to specify the data types of the columns. If this field is not specified, columns are inferred from the `statement` field by Snowflake.",
DiffSuppressFunc: IgnoreNewEmptyList([]string{"column_name"}),
DiffSuppressFunc: IgnoreNewEmptyListOrSubfields("column_name"),
},
"comment": {
Type: schema.TypeString,
Expand Down

0 comments on commit c4cf1a5

Please sign in to comment.