Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeline should not overwrite existing data #333

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Types of changes
- `Fixed` performance issue with `pipe` mask
- `Fixed` performance issue with selectors
- `Fixed` URI resources will be loaded in-memory only once instead of once per mask
- `Fixed` `timeline` should not overwrite existing data

## [1.26.2]

Expand Down
6 changes: 5 additions & 1 deletion pkg/timeline/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,23 @@ func (me MaskEngine) Mask(e model.Entry, context ...model.Dictionary) (model.Ent
}
}

var result model.Dictionary

initialState := map[string]*int64{}
if dict, ok := e.(model.Dictionary); ok {
result = dict
for _, key := range dict.Keys() {
initialState[key] = me.formatTimestamp(dict.Get(key))
}
} else {
result = model.NewDictionary()
}

timestamps, err := me.Generate(me.rand, initialState)
if err != nil {
return nil, err
}

result := model.NewDictionary()
result.Set(me.Generator.Origin(), me.formatDate(*(timestamps[me.Generator.Origin()])))
for _, point := range me.points {
value := timestamps[point]
Expand Down
33 changes: 33 additions & 0 deletions test/suites/masking_timeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,36 @@ testcases:
- result.code ShouldEqual 0
- result.systemoutjson.timeline.birth ShouldEqual "1985-06-09"
- result.systemerr ShouldBeEmpty

- name: should not overwrite existing data
steps:
- script: rm -f masking.yml
- script: |-
cat > masking.yml <<EOF
version: "1"
masking:
- selector:
jsonpath: "timeline"
masks:
- add:
departure: ""
arrival: ""
status: "COMPLETED"
- timeline:
format: "2006-01-02T15:04"
start:
name: "now"
points:
- name: "departure"
min: "-P1Y"
max: "P0"
- name: "arrival"
from: "departure"
min: "P0"
max: "PT10H"
EOF
- script: pimo --empty-input
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.timeline.status ShouldEqual "COMPLETED"
- result.systemerr ShouldBeEmpty
Loading