package processing import ( "encoding/json" "testing" ) func TestAttrsForPersist_nilAllowlistSanitizeOnly(t *testing.T) { got := AttrsForPersist(map[string]any{ "name": "TV Mount", "brand": "Ostalo", "zavora": "Mehanska", }, nil) if _, ok := got["name"]; ok { t.Fatalf("name must be stripped: %v", got) } if got["zavora"] != "Mehanska" { t.Fatalf("nil allowlist keeps non-reserved: %v", got) } } func TestCompactJSON_stable(t *testing.T) { a := []byte(`{"b":1,"a":2}`) b := []byte(`{ "a" : 2 , "b" : 1 }`) ca := compactJSON(a) cb := compactJSON(b) var ma, mb map[string]any if err := json.Unmarshal(ca, &ma); err != nil { t.Fatal(err) } if err := json.Unmarshal(cb, &mb); err != nil { t.Fatal(err) } if ma["a"] != mb["a"] || ma["b"] != mb["b"] { t.Fatalf("compact mismatch %s vs %s", ca, cb) } } func TestDecodeAttrMap_objectAndKeyedArray(t *testing.T) { obj := decodeAttrMap([]byte(`{"brand":"Ostalo","zavora":"x"}`)) if obj["brand"] != "Ostalo" { t.Fatalf("obj=%v", obj) } arr := decodeAttrMap([]byte(`[{"key":"brand","value":"Ostalo"},{"key":"zavora","value":"x"}]`)) if _, ok := arr["brand"]; !ok { t.Fatalf("arr=%v", arr) } }