diff --git a/query/gremlin/gremlin_test.go b/query/gremlin/gremlin_test.go index bd4d072..52269b7 100644 --- a/query/gremlin/gremlin_test.go +++ b/query/gremlin/gremlin_test.go @@ -15,18 +15,21 @@ package gremlin import ( + "io" + "os" "reflect" "sort" "testing" "github.com/google/cayley/graph" "github.com/google/cayley/quad" + "github.com/google/cayley/quad/cquads" _ "github.com/google/cayley/graph/memstore" _ "github.com/google/cayley/writer" ) -// This is a simple test graph. +// This is a simple test graph used for testing the gremlin queries // // +-------+ +------+ // | alice |----- ->| fred |<-- @@ -40,20 +43,6 @@ import ( // +--------+ // -var simpleGraph = []quad.Quad{ - {"alice", "follows", "bob", ""}, - {"charlie", "follows", "bob", ""}, - {"charlie", "follows", "dani", ""}, - {"dani", "follows", "bob", ""}, - {"bob", "follows", "fred", ""}, - {"fred", "follows", "greg", ""}, - {"dani", "follows", "greg", ""}, - {"emily", "follows", "fred", ""}, - {"bob", "status", "cool_person", "status_graph"}, - {"dani", "status", "cool_person", "status_graph"}, - {"greg", "status", "cool_person", "status_graph"}, -} - func makeTestSession(data []quad.Quad) *Session { qs, _ := graph.NewQuadStore("memstore", "", nil) w, _ := graph.NewQuadWriter("single", qs, nil) @@ -282,7 +271,29 @@ func runQueryGetTag(g []quad.Quad, query string, tag string) []string { return results } +func loadGraph(path string, t testing.TB) []quad.Quad { + var r io.Reader + var simpleGraph []quad.Quad + f, err := os.Open(path) + if err != nil { + t.Fatalf("Failed to open %q: %v", path, err) + } + defer f.Close() + r = f + + dec := cquads.NewDecoder(r) + q1, err := dec.Unmarshal() + if err != nil { + t.Fatalf("Failed to Unmarshal: %v", err) + } + for ; err == nil; q1, err = dec.Unmarshal() { + simpleGraph = append(simpleGraph, q1) + } + return simpleGraph +} + func TestGremlin(t *testing.T) { + simpleGraph := loadGraph("../../data/testdata.nq", t) for _, test := range testQueries { if test.tag == "" { test.tag = TopResultTag diff --git a/query/gremlin/gremlin_test.nt b/query/gremlin/gremlin_test.nt deleted file mode 100644 index 3febca3..0000000 --- a/query/gremlin/gremlin_test.nt +++ /dev/null @@ -1,11 +0,0 @@ -A follows B . -C follows B . -C follows D . -D follows B . -B follows F . -F follows G . -D follows G . -E follows F . -B status cool . -D status cool . -G status cool .