Skip to content

Commit 934d4a1

Browse files
committed
multi-label test
1 parent f701bd2 commit 934d4a1

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

client_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,29 @@ func TestUtils(t *testing.T) {
430430
assert.Equal(t, res, "{object: {foo: 1}}")
431431
}
432432

433+
func TestMultiLabelNode(t *testing.T) {
434+
// clear database
435+
graph.Flush()
436+
err := graph.Delete()
437+
assert.Nil(t, err)
438+
439+
// create a multi label node
440+
multiLabelNode := NodeNew([]string{"A","B"}, nil)
441+
graph.AddNode(multiLabelNode)
442+
res, err := graph.Commit()
443+
444+
// fetch node
445+
res, err = graph.Query("MATCH (n) RETURN n")
446+
res.Next()
447+
r := res.Record()
448+
n := r.GetByIndex(0).(*Node)
449+
450+
// expecting 2 labels
451+
assert.Equal(t, len(n.Labels), 2, "expecting 2 labels")
452+
assert.Equal(t, n.Labels[0], "A")
453+
assert.Equal(t, n.Labels[1], "B")
454+
}
455+
433456
func TestNodeMapDatatype(t *testing.T) {
434457
graph.Flush()
435458
err := graph.Delete()

edge.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Edge struct {
1717
graph *Graph
1818
}
1919

20+
// Create a new Edge
2021
func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[string]interface{}) *Edge {
2122
p := properties
2223
if p == nil {
@@ -32,15 +33,18 @@ func EdgeNew(relation string, srcNode *Node, destNode *Node, properties map[stri
3233
}
3334
}
3435

36+
// Assign a new property to edge
3537
func (e *Edge) SetProperty(key string, value interface{}) {
3638
e.Properties[key] = value
3739
}
3840

41+
// Retrieves property from edge
3942
func (e *Edge) GetProperty(key string) interface{} {
4043
v, _ := e.Properties[key]
4144
return v
4245
}
4346

47+
// Returns edge source node ID
4448
func (e Edge) SourceNodeID() uint64 {
4549
if e.Source != nil {
4650
return e.Source.ID
@@ -49,6 +53,7 @@ func (e Edge) SourceNodeID() uint64 {
4953
}
5054
}
5155

56+
// Returns edge destination node ID
5257
func (e Edge) DestNodeID() uint64 {
5358
if e.Source != nil {
5459
return e.Destination.ID
@@ -57,6 +62,7 @@ func (e Edge) DestNodeID() uint64 {
5762
}
5863
}
5964

65+
// Returns a string representation of edge
6066
func (e Edge) String() string {
6167
if len(e.Properties) == 0 {
6268
return "{}"
@@ -71,6 +77,7 @@ func (e Edge) String() string {
7177
return s
7278
}
7379

80+
// String makes Edge satisfy the Stringer interface
7481
func (e Edge) Encode() string {
7582
s := []string{"(", e.Source.Alias, ")"}
7683

node.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
)
77

8-
// Node represents a node within a graph.
8+
// Node represents a node within a graph
99
type Node struct {
1010
ID uint64
1111
Labels []string
@@ -14,6 +14,7 @@ type Node struct {
1414
graph *Graph
1515
}
1616

17+
// Create a new Node
1718
func NodeNew(labels []string, alias string, properties map[string]interface{}) *Node {
1819

1920
p := properties
@@ -29,15 +30,18 @@ func NodeNew(labels []string, alias string, properties map[string]interface{}) *
2930
}
3031
}
3132

33+
// Asssign a new property to node
3234
func (n *Node) SetProperty(key string, value interface{}) {
3335
n.Properties[key] = value
3436
}
3537

38+
// Retrieves property from node
3639
func (n Node) GetProperty(key string) interface{} {
3740
v, _ := n.Properties[key]
3841
return v
3942
}
4043

44+
// Returns a string representation of a node
4145
func (n Node) String() string {
4246
if len(n.Properties) == 0 {
4347
return "{}"
@@ -52,7 +56,7 @@ func (n Node) String() string {
5256
return s
5357
}
5458

55-
// String makes Node satisfy the Stringer interface.
59+
// String makes Node satisfy the Stringer interface
5660
func (n Node) Encode() string {
5761
s := []string{"("}
5862

query_result.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type QueryResult struct {
5959
header QueryResultHeader
6060
results []*Record
6161
statistics map[string]float64
62-
current_record_idx int
62+
currentRecordIdx int
6363
}
6464

6565
func QueryResultNew(g *Graph, response interface{}) (*QueryResult, error) {
@@ -175,10 +175,10 @@ func (qr *QueryResult) parseNode(cell interface{}) *Node {
175175

176176
c, _ := redis.Values(cell, nil)
177177
id, _ := redis.Uint64(c[0], nil)
178-
label_ids, _ := redis.Ints(c[1], nil)
179-
labels := make([]string, len(label_ids))
180-
for i := 0; i < len(label_ids); i++ {
181-
labels[i] = qr.graph.getLabel(label_ids[i])
178+
labelIds, _ := redis.Ints(c[1], nil)
179+
labels := make([]string, len(labelIds))
180+
for i := 0; i < len(labelIds); i++ {
181+
labels[i] = qr.graph.getLabel(labelIds[i])
182182
}
183183

184184
rawProps, _ := redis.Values(c[2], nil)

0 commit comments

Comments
 (0)