fix serialization casing
This commit is contained in:
parent
4e3c207e04
commit
b6ac1e8114
2 changed files with 27 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package d2graph
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"oss.terrastruct.com/util-go/go2"
|
||||
)
|
||||
|
|
@ -48,7 +49,7 @@ func DeserializeGraph(bytes []byte, g *Graph) error {
|
|||
for _, id := range so["ChildrenArray"].([]interface{}) {
|
||||
o := idToObj[id.(string)]
|
||||
childrenArray = append(childrenArray, o)
|
||||
children[id.(string)] = o
|
||||
children[strings.ToLower(id.(string))] = o
|
||||
|
||||
o.Parent = idToObj[so["AbsID"].(string)]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ func TestSerialization(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
g, err := d2compiler.Compile("", strings.NewReader("a.a.b -> a.a.c"), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
|
||||
asserts := func(g *d2graph.Graph) {
|
||||
assert.Equal(t, 4, len(g.Objects))
|
||||
|
|
@ -41,15 +39,33 @@ func TestSerialization(t *testing.T) {
|
|||
asserts(g)
|
||||
|
||||
b, err := d2graph.SerializeGraph(g)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
|
||||
var newG d2graph.Graph
|
||||
err = d2graph.DeserializeGraph(b, &newG)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
|
||||
asserts(&newG)
|
||||
}
|
||||
|
||||
func TestCasingRegression(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
script := `UserCreatedTypeField`
|
||||
|
||||
g, err := d2compiler.Compile("", strings.NewReader(script), nil)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, ok := g.Root.HasChild([]string{"UserCreatedTypeField"})
|
||||
assert.True(t, ok)
|
||||
|
||||
b, err := d2graph.SerializeGraph(g)
|
||||
assert.Nil(t, err)
|
||||
|
||||
var newG d2graph.Graph
|
||||
err = d2graph.DeserializeGraph(b, &newG)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, ok = newG.Root.HasChild([]string{"UserCreatedTypeField"})
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue