Skip to content

Commit

Permalink
Fix generate change diff on Struct
Browse files Browse the repository at this point in the history
Since we have the filteredValue variable, we need to use the same
variable when we are trying to generate the Diffs. So I fix it by
changing the variable that need to be compared.
  • Loading branch information
haritsfahreza committed Dec 10, 2020
1 parent 1b4215a commit 6b4d5cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/comparator/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *StructComparator) Compare(ctx context.Context, oldVal, newVal reflect.V
continue
}

if diff := diff.GenerateChangedDiff(ctx, typeField.Name, oldField, newField); diff != nil {
if diff := diff.GenerateChangedDiff(ctx, typeField.Name, filteredOldValue, filteredNewValue); diff != nil {
diffs = append(diffs, *diff)
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/diff/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func GenerateRemovedDiff(ctx context.Context, obj reflect.Value) Diff {

func GenerateChangedDiff(ctx context.Context, fieldName string, oldVal, newVal reflect.Value) *Diff {
var oldI, newI interface{}

if !oldVal.IsValid() || !newVal.IsValid() {
return nil
}

switch oldVal.Kind() {
case reflect.Array, reflect.Slice:
oldI = reflectArrayToString(ctx, oldVal)
Expand Down

0 comments on commit 6b4d5cf

Please sign in to comment.