MCPcopy Create free account
hub / github.com/RedisGraph/redisgraph-go / TestPath

Function TestPath

client_test.go:268–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

266}
267
268func TestPath(t *testing.T) {
269 createGraph()
270 q := "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p"
271 res, err := graph.Query(q)
272 if err != nil {
273 t.Error(err)
274 }
275
276 assert.Equal(t, len(res.results), 1, "expecting 1 result record")
277
278 res.Next()
279 r := res.Record()
280
281 p, ok := r.GetByIndex(0).(Path)
282 assert.True(t, ok, "First column should contain path.")
283
284 assert.Equal(t, 2, p.NodesCount(), "Path should contain two nodes")
285 assert.Equal(t, 1, p.EdgeCount(), "Path should contain one edge")
286
287 s := p.FirstNode()
288 e := p.GetEdge(0)
289 d := p.LastNode()
290
291 assert.Equal(t, s.Label, "Person", "Node should be of type 'Person'")
292 assert.Equal(t, e.Relation, "Visited", "Edge should be of relation type 'Visited'")
293 assert.Equal(t, d.Label, "Country", "Node should be of type 'Country'")
294
295 assert.Equal(t, len(s.Properties), 4, "Person node should have 4 properties")
296
297 assert.Equal(t, s.GetProperty("name"), "John Doe", "Unexpected property value.")
298 assert.Equal(t, s.GetProperty("age"), 33, "Unexpected property value.")
299 assert.Equal(t, s.GetProperty("gender"), "male", "Unexpected property value.")
300 assert.Equal(t, s.GetProperty("status"), "single", "Unexpected property value.")
301
302 assert.Equal(t, e.GetProperty("year"), 2017, "Unexpected property value.")
303
304 assert.Equal(t, d.GetProperty("name"), "Japan", "Unexpected property value.")
305 assert.Equal(t, d.GetProperty("population"), 126800000, "Unexpected property value.")
306
307}
308
309func TestParameterizedQuery(t *testing.T) {
310 createGraph()

Callers

nothing calls this directly

Calls 11

createGraphFunction · 0.85
QueryMethod · 0.80
NextMethod · 0.80
RecordMethod · 0.80
GetByIndexMethod · 0.80
NodesCountMethod · 0.80
EdgeCountMethod · 0.80
FirstNodeMethod · 0.80
GetEdgeMethod · 0.80
LastNodeMethod · 0.80
GetPropertyMethod · 0.45

Tested by

no test coverage detected