Skip to content

Commit

Permalink
pass map representation of proto duration for patch of delete_version…
Browse files Browse the repository at this point in the history
…_after (#62)
  • Loading branch information
ccapurso authored Jun 3, 2022
1 parent a1df167 commit c840ea6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion path_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,17 @@ func metadataPatchPreprocessor() framework.PatchPreprocessorFunc {
for _, k := range patchableKeys {
if v, ok := input[k]; ok {
if k == "delete_version_after" {
patchData[k] = ptypes.DurationProto(time.Duration(v.(int)) * time.Second)
d := ptypes.DurationProto(time.Duration(v.(int)) * time.Second)

// underlying Seconds and Nanos fields in durationpb.Duration
// use omitempty json tags. Providing "0s" will result in an
// empty map after JSON marshaling which will act as a noop
// come JSON merge patch time. Instead, we pass in a
// map-representation of the data to enable patching with "0s"
patchData[k] = map[string]interface{}{
"seconds": d.Seconds,
"nanos": d.Nanos,
}
} else {
patchData[k] = v
}
Expand Down
5 changes: 3 additions & 2 deletions path_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,10 @@ func TestVersionedKV_Metadata_Patch_Success(t *testing.T) {
map[string]interface{}{
"cas_required": true,
"max_versions": uint32(15),
"delete_version_after": nil,
"delete_version_after": "0s",
"updated_time": ignoreVal,
},
2,
3,
},
}

Expand All @@ -1207,6 +1207,7 @@ func TestVersionedKV_Metadata_Patch_Success(t *testing.T) {
Storage: storage,
Data: map[string]interface{}{
"max_versions": uint32(10),
"delete_version_after": "10s",
},
}

Expand Down

0 comments on commit c840ea6

Please sign in to comment.