fix deserialization of obj.children

This commit is contained in:
Júlio César Batista 2023-02-17 15:35:13 -03:00
parent d369371771
commit d1efedca9a
No known key found for this signature in database
GPG key ID: 10C4B861BF314878
2 changed files with 7 additions and 2 deletions

View file

@ -2,7 +2,6 @@ package d2graph
import (
"encoding/json"
"strings"
"oss.terrastruct.com/util-go/go2"
)
@ -49,7 +48,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error {
for _, id := range so["ChildrenArray"].([]interface{}) {
o := idToObj[id.(string)]
childrenArray = append(childrenArray, o)
children[strings.ToLower(id.(string))] = o
children[o.IDVal] = o
o.Parent = idToObj[so["AbsID"].(string)]
}

View file

@ -31,6 +31,12 @@ func TestSerialization(t *testing.T) {
g.Root.ChildrenArray[0].Parent,
)
a := g.Root.ChildrenArray[0]
aa := a.ChildrenArray[0]
assert.Contains(t, a.Children, "a")
assert.Contains(t, aa.Children, "b")
assert.Contains(t, aa.Children, "c")
assert.Equal(t, 1, len(g.Edges))
assert.Equal(t, "b", g.Edges[0].Src.ID)
assert.Equal(t, "c", g.Edges[0].Dst.ID)