@@ -16,8 +16,8 @@ func createGraph() {
16
16
graph = GraphNew ("social" , conn )
17
17
18
18
// Create 2 nodes connect via a single edge.
19
- japan := NodeNew ("Country" , "j" , nil )
20
- john := NodeNew ("Person" , "p" , nil )
19
+ japan := NodeNew ([] string { "Country" } , "j" , nil )
20
+ john := NodeNew ([] string { "Person" } , "p" , nil )
21
21
edge := EdgeNew ("Visited" , john , japan , nil )
22
22
23
23
// Set node properties.
@@ -91,9 +91,9 @@ func checkQueryResults(t *testing.T, res *QueryResult) {
91
91
d , ok := r .GetByIndex (2 ).(* Node )
92
92
assert .True (t , ok , "Third column should contain nodes." )
93
93
94
- assert .Equal (t , s .Label , "Person" , "Node should be of type 'Person'" )
94
+ assert .Equal (t , s .Labels [ 0 ] , "Person" , "Node should be of type 'Person'" )
95
95
assert .Equal (t , e .Relation , "Visited" , "Edge should be of relation type 'Visited'" )
96
- assert .Equal (t , d .Label , "Country" , "Node should be of type 'Country'" )
96
+ assert .Equal (t , d .Labels [ 0 ] , "Country" , "Node should be of type 'Country'" )
97
97
98
98
assert .Equal (t , len (s .Properties ), 4 , "Person node should have 4 properties" )
99
99
@@ -131,7 +131,7 @@ func TestCreateQuery(t *testing.T) {
131
131
res .Next ()
132
132
r := res .Record ()
133
133
w := r .GetByIndex (0 ).(* Node )
134
- assert .Equal (t , w .Label , "WorkPlace" , "Unexpected node label." )
134
+ assert .Equal (t , w .Labels [ 0 ] , "WorkPlace" , "Unexpected node label." )
135
135
}
136
136
137
137
func TestCreateROQueryFailure (t * testing.T ) {
@@ -199,8 +199,8 @@ func TestArray(t *testing.T) {
199
199
t .Error (err )
200
200
}
201
201
202
- a := NodeNew ("person" , "" , nil )
203
- b := NodeNew ("person" , "" , nil )
202
+ a := NodeNew ([] string { "person" } , "" , nil )
203
+ b := NodeNew ([] string { "person" } , "" , nil )
204
204
205
205
a .SetProperty ("name" , "a" )
206
206
a .SetProperty ("age" , 32 )
@@ -288,9 +288,9 @@ func TestPath(t *testing.T) {
288
288
e := p .GetEdge (0 )
289
289
d := p .LastNode ()
290
290
291
- assert .Equal (t , s .Label , "Person" , "Node should be of type 'Person'" )
291
+ assert .Equal (t , s .Labels [ 0 ] , "Person" , "Node should be of type 'Person'" )
292
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'" )
293
+ assert .Equal (t , d .Labels [ 0 ] , "Country" , "Node should be of type 'Country'" )
294
294
295
295
assert .Equal (t , len (s .Properties ), 4 , "Person node should have 4 properties" )
296
296
@@ -308,12 +308,12 @@ func TestPath(t *testing.T) {
308
308
309
309
func TestParameterizedQuery (t * testing.T ) {
310
310
createGraph ()
311
- params := []interface {}{1 , 2.3 , "str" , true , false , nil , []interface {}{0 , 1 , 2 }, []interface {}{"0" , "1" , "2" }}
311
+ params := []interface {}{1 , 2.3 , "str" , true , false , nil , []interface {}{0 , 1 , 2 }, []interface {}{"0" , "1" , "2" }}
312
312
q := "RETURN $param"
313
313
params_map := make (map [string ]interface {})
314
314
for index , param := range params {
315
315
params_map ["param" ] = param
316
- res , err := graph .ParameterizedQuery (q , params_map );
316
+ res , err := graph .ParameterizedQuery (q , params_map )
317
317
if err != nil {
318
318
t .Error (err )
319
319
}
@@ -348,24 +348,24 @@ func TestCreateIndex(t *testing.T) {
348
348
func TestQueryStatistics (t * testing.T ) {
349
349
graph .Flush ()
350
350
err := graph .Delete ()
351
- assert .Nil (t ,err )
351
+ assert .Nil (t , err )
352
352
353
353
q := "CREATE (:Person{name:'a',age:32,array:[0,1,2]})"
354
354
res , err := graph .Query (q )
355
- assert .Nil (t ,err )
355
+ assert .Nil (t , err )
356
356
357
357
assert .Equal (t , 1 , res .NodesCreated (), "Expecting 1 node created" )
358
358
assert .Equal (t , 0 , res .NodesDeleted (), "Expecting 0 nodes deleted" )
359
- assert .Greater (t , res .InternalExecutionTime (),0.0 , "Expecting internal execution time not to be 0.0" )
359
+ assert .Greater (t , res .InternalExecutionTime (), 0.0 , "Expecting internal execution time not to be 0.0" )
360
360
assert .Equal (t , true , res .Empty (), "Expecting empty resultset" )
361
361
362
- res ,err = graph .Query ("MATCH (n) DELETE n" )
363
- assert .Nil (t ,err )
362
+ res , err = graph .Query ("MATCH (n) DELETE n" )
363
+ assert .Nil (t , err )
364
364
assert .Equal (t , 1 , res .NodesDeleted (), "Expecting 1 nodes deleted" )
365
365
366
366
// Create 2 nodes connect via a single edge.
367
- japan := NodeNew ("Country" , "j" , nil )
368
- john := NodeNew ("Person" , "p" , nil )
367
+ japan := NodeNew ([] string { "Country" } , "j" , nil )
368
+ john := NodeNew ([] string { "Person" } , "p" , nil )
369
369
edge := EdgeNew ("Visited" , john , japan , nil )
370
370
371
371
// Set node properties.
@@ -386,21 +386,21 @@ func TestQueryStatistics(t *testing.T) {
386
386
387
387
// Flush graph to DB.
388
388
res , err = graph .Commit ()
389
- assert .Nil (t ,err )
389
+ assert .Nil (t , err )
390
390
assert .Equal (t , 2 , res .NodesCreated (), "Expecting 2 node created" )
391
391
assert .Equal (t , 0 , res .NodesDeleted (), "Expecting 0 nodes deleted" )
392
392
assert .Equal (t , 7 , res .PropertiesSet (), "Expecting 7 properties set" )
393
393
assert .Equal (t , 1 , res .RelationshipsCreated (), "Expecting 1 relationships created" )
394
394
assert .Equal (t , 0 , res .RelationshipsDeleted (), "Expecting 0 relationships deleted" )
395
- assert .Greater (t , res .InternalExecutionTime (),0.0 , "Expecting internal execution time not to be 0.0" )
395
+ assert .Greater (t , res .InternalExecutionTime (), 0.0 , "Expecting internal execution time not to be 0.0" )
396
396
assert .Equal (t , true , res .Empty (), "Expecting empty resultset" )
397
397
q = "MATCH p = (:Person)-[:Visited]->(:Country) RETURN p"
398
398
res , err = graph .Query (q )
399
- assert .Nil (t ,err )
399
+ assert .Nil (t , err )
400
400
assert .Equal (t , len (res .results ), 1 , "expecting 1 result record" )
401
401
assert .Equal (t , false , res .Empty (), "Expecting resultset to have records" )
402
- res ,err = graph .Query ("MATCH ()-[r]-() DELETE r" )
403
- assert .Nil (t ,err )
402
+ res , err = graph .Query ("MATCH ()-[r]-() DELETE r" )
403
+ assert .Nil (t , err )
404
404
assert .Equal (t , 1 , res .RelationshipsDeleted (), "Expecting 1 relationships deleted" )
405
405
}
406
406
@@ -410,39 +410,65 @@ func TestUtils(t *testing.T) {
410
410
411
411
res = ToString ("test_string" )
412
412
assert .Equal (t , res , "\" test_string\" " )
413
-
413
+
414
414
res = ToString (10 )
415
- assert .Equal (t , res , "10" )
415
+ assert .Equal (t , res , "10" )
416
416
417
417
res = ToString (1.2 )
418
418
assert .Equal (t , res , "1.2" )
419
419
420
420
res = ToString (true )
421
421
assert .Equal (t , res , "true" )
422
422
423
- var arr = []interface {}{1 ,2 , 3 , "boom" }
423
+ var arr = []interface {}{1 , 2 , 3 , "boom" }
424
424
res = ToString (arr )
425
425
assert .Equal (t , res , "[1,2,3,\" boom\" ]" )
426
-
426
+
427
427
jsonMap := make (map [string ]interface {})
428
- jsonMap ["object" ] = map [string ]interface {} {"foo" : 1 }
428
+ jsonMap ["object" ] = map [string ]interface {}{"foo" : 1 }
429
429
res = ToString (jsonMap )
430
430
assert .Equal (t , res , "{object: {foo: 1}}" )
431
431
}
432
432
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" }, "n" , nil )
441
+ graph .AddNode (multiLabelNode )
442
+ _ , err = graph .Commit ()
443
+ assert .Nil (t , err )
444
+
445
+ // fetch node
446
+ res , err := graph .Query ("MATCH (n) RETURN n" )
447
+ assert .Nil (t , err )
448
+
449
+ res .Next ()
450
+ r := res .Record ()
451
+ n := r .GetByIndex (0 ).(* Node )
452
+
453
+ // expecting 2 labels
454
+ assert .Equal (t , len (n .Labels ), 2 , "expecting 2 labels" )
455
+ assert .Equal (t , n .Labels [0 ], "A" )
456
+ assert .Equal (t , n .Labels [1 ], "B" )
457
+ }
458
+
433
459
func TestNodeMapDatatype (t * testing.T ) {
434
460
graph .Flush ()
435
461
err := graph .Delete ()
436
462
assert .Nil (t , err )
437
463
438
464
// Create 2 nodes connect via a single edge.
439
- japan := NodeNew ("Country" , "j" ,
465
+ japan := NodeNew ([] string { "Country" } , "j" ,
440
466
map [string ]interface {}{
441
467
"name" : "Japan" ,
442
468
"population" : 126800000 ,
443
469
"states" : []string {"Kanto" , "Chugoku" },
444
470
})
445
- john := NodeNew ("Person" , "p" ,
471
+ john := NodeNew ([] string { "Person" } , "p" ,
446
472
map [string ]interface {}{
447
473
"name" : "John Doe" ,
448
474
"age" : 33 ,
@@ -488,7 +514,7 @@ func TestTimeout(t *testing.T) {
488
514
489
515
params := make (map [string ]interface {})
490
516
params ["ub" ] = 1000000
491
- res , err = graph .ParameterizedQueryWithOptions ("UNWIND range(0, $ub) AS v RETURN v" , params , options );
517
+ res , err = graph .ParameterizedQueryWithOptions ("UNWIND range(0, $ub) AS v RETURN v" , params , options )
492
518
assert .Nil (t , res )
493
519
assert .NotNil (t , err )
494
520
}
0 commit comments