mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-01 12:31:59 +00:00
Update handlers skipped empty strings and nulls, so a client could not
blank or null out a column. Every key present in the payload now
overwrites the stored value, including "" and null.
- add common.MergeUpdateValues and use it in resolvespec and restheadspec
- add Handler.SetDisallowNulls to skip null values (""still overwrites)
- websocketspec and mqttspec now write only the keys present in the
payload via SetMap instead of updating the whole zeroed model, which
clobbered absent fields
30 lines
840 B
Go
30 lines
840 B
Go
package common
|
|
|
|
import "testing"
|
|
|
|
func TestMergeUpdateValues(t *testing.T) {
|
|
newExisting := func() map[string]interface{} {
|
|
return map[string]interface{}{"name": "old", "note": "keep", "other": "x"}
|
|
}
|
|
incoming := map[string]interface{}{"name": "", "note": nil}
|
|
|
|
got := MergeUpdateValues(newExisting(), incoming, false)
|
|
if got["name"] != "" {
|
|
t.Errorf("name = %v, want empty string", got["name"])
|
|
}
|
|
if v, ok := got["note"]; !ok || v != nil {
|
|
t.Errorf("note = %v (present=%v), want nil", v, ok)
|
|
}
|
|
if got["other"] != "x" {
|
|
t.Errorf("absent key changed: %v", got["other"])
|
|
}
|
|
|
|
got = MergeUpdateValues(newExisting(), incoming, true)
|
|
if got["name"] != "" {
|
|
t.Errorf("disallowNulls: name = %v, want empty string", got["name"])
|
|
}
|
|
if got["note"] != "keep" {
|
|
t.Errorf("disallowNulls: note = %v, want keep", got["note"])
|
|
}
|
|
}
|