@@ -65,6 +65,20 @@ func TestMatchQuery(t *testing.T) {
65
65
t .Error (err )
66
66
}
67
67
68
+ checkQueryResults (t , res )
69
+ }
70
+
71
+ func TestMatchROQuery (t * testing.T ) {
72
+ q := "MATCH (s)-[e]->(d) RETURN s,e,d"
73
+ res , err := graph .ROQuery (q )
74
+ if err != nil {
75
+ t .Error (err )
76
+ }
77
+
78
+ checkQueryResults (t , res )
79
+ }
80
+
81
+ func checkQueryResults (t * testing.T , res * QueryResult ) {
68
82
assert .Equal (t , len (res .results ), 1 , "expecting 1 result record" )
69
83
70
84
res .Next ()
@@ -120,6 +134,12 @@ func TestCreateQuery(t *testing.T) {
120
134
assert .Equal (t , w .Label , "WorkPlace" , "Unexpected node label." )
121
135
}
122
136
137
+ func TestCreateROQueryFailure (t * testing.T ) {
138
+ q := "CREATE (w:WorkPlace {name:'RedisLabs'})"
139
+ _ , err := graph .ROQuery (q )
140
+ assert .NotNil (t , err , "error should not be nil" )
141
+ }
142
+
123
143
func TestErrorReporting (t * testing.T ) {
124
144
q := "RETURN toupper(5)"
125
145
res , err := graph .Query (q )
@@ -399,3 +419,73 @@ func TestQueryStatistics(t *testing.T) {
399
419
assert .Nil (t ,err )
400
420
assert .Equal (t , 1 , res .RelationshipsDeleted (), "Expecting 1 relationships deleted" )
401
421
}
422
+
423
+ func TestUtils (t * testing.T ) {
424
+ res := RandomString (10 )
425
+ assert .Equal (t , len (res ), 10 )
426
+
427
+ res = ToString ("test_string" )
428
+ assert .Equal (t , res , "\" test_string\" " )
429
+
430
+ res = ToString (10 )
431
+ assert .Equal (t , res , "10" )
432
+
433
+ res = ToString (1.2 )
434
+ assert .Equal (t , res , "1.2" )
435
+
436
+ res = ToString (true )
437
+ assert .Equal (t , res , "true" )
438
+
439
+ var arr = []interface {}{1 ,2 ,3 ,"boom" }
440
+ res = ToString (arr )
441
+ assert .Equal (t , res , "[1,2,3,\" boom\" ]" )
442
+
443
+ jsonMap := make (map [string ]interface {})
444
+ jsonMap ["object" ] = map [string ]interface {} {"foo" : 1 }
445
+ res = ToString (jsonMap )
446
+ assert .Equal (t , res , "{object: {foo: 1}}" )
447
+ }
448
+
449
+ func TestNodeMapDatatype (t * testing.T ) {
450
+ graph .Flush ()
451
+ err := graph .Delete ()
452
+ assert .Nil (t , err )
453
+
454
+ // Create 2 nodes connect via a single edge.
455
+ japan := NodeNew ("Country" , "j" ,
456
+ map [string ]interface {}{
457
+ "name" : "Japan" ,
458
+ "population" : 126800000 ,
459
+ "states" : []string {"Kanto" , "Chugoku" },
460
+ })
461
+ john := NodeNew ("Person" , "p" ,
462
+ map [string ]interface {}{
463
+ "name" : "John Doe" ,
464
+ "age" : 33 ,
465
+ "gender" : "male" ,
466
+ "status" : "single" ,
467
+ })
468
+ edge := EdgeNew ("Visited" , john , japan , map [string ]interface {}{"year" : 2017 })
469
+ // Introduce entities to graph.
470
+ graph .AddNode (john )
471
+ graph .AddNode (japan )
472
+ graph .AddEdge (edge )
473
+
474
+ // Flush graph to DB.
475
+ res , err := graph .Commit ()
476
+ assert .Nil (t , err )
477
+ assert .Equal (t , 2 , res .NodesCreated (), "Expecting 2 node created" )
478
+ assert .Equal (t , 0 , res .NodesDeleted (), "Expecting 0 nodes deleted" )
479
+ assert .Equal (t , 8 , res .PropertiesSet (), "Expecting 8 properties set" )
480
+ assert .Equal (t , 1 , res .RelationshipsCreated (), "Expecting 1 relationships created" )
481
+ assert .Equal (t , 0 , res .RelationshipsDeleted (), "Expecting 0 relationships deleted" )
482
+ assert .Greater (t , res .InternalExecutionTime (), 0.0 , "Expecting internal execution time not to be 0.0" )
483
+ assert .Equal (t , true , res .Empty (), "Expecting empty resultset" )
484
+ res , err = graph .Query ("MATCH p = (:Person)-[:Visited]->(:Country) RETURN p" )
485
+ assert .Nil (t , err )
486
+ assert .Equal (t , len (res .results ), 1 , "expecting 1 result record" )
487
+ assert .Equal (t , false , res .Empty (), "Expecting resultset to have records" )
488
+ res , err = graph .Query ("MATCH ()-[r]-() DELETE r" )
489
+ assert .Nil (t , err )
490
+ assert .Equal (t , 1 , res .RelationshipsDeleted (), "Expecting 1 relationships deleted" )
491
+ }
0 commit comments