Skip to content

Commit

Permalink
fix: do not change created_at on entity updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Oct 25, 2023
1 parent d9c5e22 commit 8a596eb
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 43 deletions.
22 changes: 19 additions & 3 deletions diff/diff_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
"github.com/kong/deck/state"
"github.com/kong/deck/utils"
)

var differ = gojsondiff.New()
Expand Down Expand Up @@ -61,8 +60,6 @@ func prettyPrintJSONString(JSONString string) (string, error) {
}

func getDiff(a, b interface{}) (string, error) {
utils.ZeroOutTimestamps(a)
utils.ZeroOutTimestamps(b)
aJSON, err := json.Marshal(a)
if err != nil {
return "", err
Expand All @@ -71,6 +68,11 @@ func getDiff(a, b interface{}) (string, error) {
if err != nil {
return "", err
}

// remove timestamps from JSON data without modifying the original data
aJSON = removeTimestamps(aJSON)
bJSON = removeTimestamps(bJSON)

d, err := differ.Compare(aJSON, bJSON)
if err != nil {
return "", err
Expand All @@ -87,6 +89,20 @@ func getDiff(a, b interface{}) (string, error) {
return diffString, err
}

func removeTimestamps(jsonData []byte) []byte {
var dataMap map[string]interface{}
if err := json.Unmarshal(jsonData, &dataMap); err != nil {
return jsonData
}
delete(dataMap, "created_at")
delete(dataMap, "updated_at")
modifiedJSON, err := json.Marshal(dataMap)
if err != nil {
return jsonData
}
return modifiedJSON
}

type EnvVar struct {
Key string
Value string
Expand Down
Loading

0 comments on commit 8a596eb

Please sign in to comment.