Files
ent/dialect/gremlin/graph/edge_test.go
Ariel Mashraki 1e47de5300 move lib/go/gremlin to ent/dialect (#1192)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1192

Pull Request resolved: https://github.com/facebookincubator/ent/pull/11

Reviewed By: alexsn

Differential Revision: D16377224

fbshipit-source-id: 07ca7436eb9b64fbe2299568560b91466b2417ba
2019-07-20 08:27:06 -07:00

105 lines
1.9 KiB
Go

package graph
import (
"fmt"
"testing"
"fbc/ent/dialect/gremlin/encoding/graphson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEdgeString(t *testing.T) {
e := NewEdge(
13, "develops",
NewVertex(1, ""),
NewVertex(10, ""),
)
assert.Equal(t, "e[13][1-develops->10]", fmt.Sprint(e))
}
func TestEdgeEncoding(t *testing.T) {
t.Parallel()
e := NewEdge(13, "develops",
NewVertex(1, "person"),
NewVertex(10, "software"),
)
got, err := graphson.MarshalToString(e)
require.NoError(t, err)
want := `{
"@type" : "g:Edge",
"@value" : {
"id" : {
"@type" : "g:Int64",
"@value" : 13
},
"label" : "develops",
"inVLabel" : "software",
"outVLabel" : "person",
"inV" : {
"@type" : "g:Int64",
"@value" : 10
},
"outV" : {
"@type" : "g:Int64",
"@value" : 1
}
}
}`
assert.JSONEq(t, want, got)
e = Edge{}
err = graphson.UnmarshalFromString(got, &e)
require.NoError(t, err)
assert.Equal(t, NewElement(int64(13), "develops"), e.Element)
assert.Equal(t, NewVertex(int64(1), "person"), e.OutV)
assert.Equal(t, NewVertex(int64(10), "software"), e.InV)
}
func TestPropertyEncoding(t *testing.T) {
t.Parallel()
props := []Property{
NewProperty("from", int32(2017)),
NewProperty("to", int32(2019)),
}
got, err := graphson.MarshalToString(props)
require.NoError(t, err)
want := `{
"@type" : "g:List",
"@value" : [
{
"@type" : "g:Property",
"@value" : {
"key" : "from",
"value" : {
"@type" : "g:Int32",
"@value" : 2017
}
}
},
{
"@type" : "g:Property",
"@value" : {
"key" : "to",
"value" : {
"@type" : "g:Int32",
"@value" : 2019
}
}
}
]
}`
assert.JSONEq(t, want, got)
}
func TestPropertyString(t *testing.T) {
p := NewProperty("since", 2019)
assert.Equal(t, "p[since->2019]", fmt.Sprint(p))
}