fix deserialization of obj.children
This commit is contained in:
parent
d369371771
commit
d1efedca9a
2 changed files with 7 additions and 2 deletions
|
|
@ -2,7 +2,6 @@ package d2graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"oss.terrastruct.com/util-go/go2"
|
"oss.terrastruct.com/util-go/go2"
|
||||||
)
|
)
|
||||||
|
|
@ -49,7 +48,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error {
|
||||||
for _, id := range so["ChildrenArray"].([]interface{}) {
|
for _, id := range so["ChildrenArray"].([]interface{}) {
|
||||||
o := idToObj[id.(string)]
|
o := idToObj[id.(string)]
|
||||||
childrenArray = append(childrenArray, o)
|
childrenArray = append(childrenArray, o)
|
||||||
children[strings.ToLower(id.(string))] = o
|
children[o.IDVal] = o
|
||||||
|
|
||||||
o.Parent = idToObj[so["AbsID"].(string)]
|
o.Parent = idToObj[so["AbsID"].(string)]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ func TestSerialization(t *testing.T) {
|
||||||
g.Root.ChildrenArray[0].Parent,
|
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, 1, len(g.Edges))
|
||||||
assert.Equal(t, "b", g.Edges[0].Src.ID)
|
assert.Equal(t, "b", g.Edges[0].Src.ID)
|
||||||
assert.Equal(t, "c", g.Edges[0].Dst.ID)
|
assert.Equal(t, "c", g.Edges[0].Dst.ID)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue