@@ -22,10 +22,12 @@ package test_integration
22
22
import (
23
23
"github.com/neo4j/neo4j-go-driver/neo4j"
24
24
"github.com/neo4j/neo4j-go-driver/neo4j/test-integration/control"
25
+ . "github.com/neo4j/neo4j-go-driver/neo4j/utils/test"
25
26
. "github.com/onsi/ginkgo"
26
27
. "github.com/onsi/ginkgo/extensions/table"
27
28
. "github.com/onsi/gomega"
28
29
"math/rand"
30
+ "reflect"
29
31
)
30
32
31
33
var _ = Describe ("Types" , func () {
@@ -417,6 +419,11 @@ var _ = Describe("Types", func() {
417
419
Entry ("int32" , (* int32 )(nil )),
418
420
Entry ("int64" , (* int64 )(nil )),
419
421
Entry ("int" , (* int )(nil )),
422
+ Entry ("uint8" , (* uint8 )(nil )),
423
+ Entry ("uint16" , (* uint16 )(nil )),
424
+ Entry ("uint32" , (* uint32 )(nil )),
425
+ Entry ("uint64" , (* uint64 )(nil )),
426
+ Entry ("uint" , (* uint )(nil )),
420
427
Entry ("float32" , (* float32 )(nil )),
421
428
Entry ("float64" , (* float64 )(nil )),
422
429
Entry ("string" , (* string )(nil )),
@@ -427,8 +434,272 @@ var _ = Describe("Types", func() {
427
434
Entry ("int32 array" , (* []int32 )(nil )),
428
435
Entry ("int64 array" , (* []int64 )(nil )),
429
436
Entry ("int array" , (* []int )(nil )),
437
+ Entry ("uint8 array" , (* []uint8 )(nil )),
438
+ Entry ("uint16 array" , (* []uint16 )(nil )),
439
+ Entry ("uint32 array" , (* []uint32 )(nil )),
440
+ Entry ("uint64 array" , (* []uint64 )(nil )),
441
+ Entry ("uint array" , (* []uint )(nil )),
430
442
Entry ("float32 array" , (* []float32 )(nil )),
431
443
Entry ("float64 array" , (* []float64 )(nil )),
432
444
Entry ("string array" , (* []string )(nil )),
433
445
)
446
+
447
+ Context ("Un-convertible Go types" , func () {
448
+ type unsupportedType struct {
449
+ }
450
+
451
+ Context ("Session.Run" , func () {
452
+ It ("should fail when sending as parameter" , func () {
453
+ result , err = session .Run ("CREATE (n {value: $value}) RETURN n.value" , map [string ]interface {}{"value" : unsupportedType {}})
454
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert parameter \" value\" to connector value for run message" )))
455
+ Expect (result ).To (BeNil ())
456
+ })
457
+
458
+ It ("should fail when sending as tx metadata" , func () {
459
+ result , err = session .Run ("CREATE (n)" , nil , neo4j .WithTxMetadata (map [string ]interface {}{"m1" : unsupportedType {}}))
460
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert tx metadata to connector value for run message" )))
461
+ Expect (result ).To (BeNil ())
462
+ })
463
+ })
464
+
465
+ Context ("Session.BeginTransaction" , func () {
466
+ var tx neo4j.Transaction
467
+
468
+ It ("should fail when sending as tx metadata" , func () {
469
+ tx , err = session .BeginTransaction (neo4j .WithTxMetadata (map [string ]interface {}{"m1" : unsupportedType {}}))
470
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert tx metadata to connector value for begin message" )))
471
+ Expect (tx ).To (BeNil ())
472
+ })
473
+ })
474
+
475
+ Context ("Session.BeginTransaction" , func () {
476
+ var tx neo4j.Transaction
477
+
478
+ It ("should fail when sending as tx metadata" , func () {
479
+ tx , err = session .BeginTransaction (neo4j .WithTxMetadata (map [string ]interface {}{"m1" : unsupportedType {}}))
480
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert tx metadata to connector value for begin message" )))
481
+ Expect (tx ).To (BeNil ())
482
+ })
483
+ })
484
+
485
+ Context ("Session.ReadTransaction" , func () {
486
+ It ("should fail when sending as tx metadata" , func () {
487
+ result , err := session .ReadTransaction (func (tx neo4j.Transaction ) (i interface {}, e error ) {
488
+ return nil , nil
489
+ }, neo4j .WithTxMetadata (map [string ]interface {}{"m1" : unsupportedType {}}))
490
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert tx metadata to connector value for begin message" )))
491
+ Expect (result ).To (BeNil ())
492
+ })
493
+ })
494
+
495
+ Context ("Session.WriteTransaction" , func () {
496
+ It ("should fail when sending as tx metadata" , func () {
497
+ result , err := session .WriteTransaction (func (tx neo4j.Transaction ) (i interface {}, e error ) {
498
+ return nil , nil
499
+ }, neo4j .WithTxMetadata (map [string ]interface {}{"m1" : unsupportedType {}}))
500
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert tx metadata to connector value for begin message" )))
501
+ Expect (result ).To (BeNil ())
502
+ })
503
+ })
504
+
505
+ Context ("Transaction.Run" , func () {
506
+ var tx neo4j.Transaction
507
+
508
+ It ("should fail when sending as tx metadata" , func () {
509
+ tx , err = session .BeginTransaction ()
510
+ Expect (err ).To (BeNil ())
511
+ Expect (tx ).NotTo (BeNil ())
512
+
513
+ result , err = tx .Run ("CREATE (n)" , map [string ]interface {}{"unsupported" : unsupportedType {}})
514
+ Expect (err ).To (BeGenericError (ContainSubstring ("unable to convert parameter \" unsupported\" to connector value for run messag" )))
515
+ Expect (result ).To (BeNil ())
516
+ })
517
+ })
518
+ })
519
+
520
+ Context ("Aliased types" , func () {
521
+ type (
522
+ booleanAlias bool
523
+ byteAlias byte
524
+ int8Alias int8
525
+ int16Alias int16
526
+ int32Alias int32
527
+ int64Alias int64
528
+ intAlias int
529
+ uint8Alias uint8
530
+ uint16Alias uint16
531
+ uint32Alias uint32
532
+ uint64Alias uint64
533
+ uintAlias uint
534
+ float32Alias float32
535
+ float64Alias float64
536
+ stringAlias string
537
+ booleanArrayAlias []bool
538
+ byteArrayAlias []byte
539
+ int8ArrayAlias []int8
540
+ int16ArrayAlias []int16
541
+ int32ArrayAlias []int32
542
+ int64ArrayAlias []int64
543
+ intArrayAlias []int
544
+ uint8ArrayAlias []uint8
545
+ uint16ArrayAlias []uint16
546
+ uint32ArrayAlias []uint32
547
+ uint64ArrayAlias []uint64
548
+ uintArrayAlias []uint
549
+ float32ArrayAlias []float32
550
+ float64ArrayAlias []float64
551
+ stringArrayAlias []string
552
+ )
553
+
554
+ var (
555
+ boolAliasValue = booleanAlias (true )
556
+ byteAliasValue = byteAlias ('A' )
557
+ int8AliasValue = int8Alias (127 )
558
+ int16AliasValue = int16Alias (- 512 )
559
+ int32AliasValue = int32Alias (- 1024 )
560
+ int64AliasValue = int64Alias (- 124798272 )
561
+ intAliasValue = intAlias (- 98937323493 )
562
+ uint8AliasValue = uint8Alias (127 )
563
+ uint16AliasValue = uint16Alias (512 )
564
+ uint32AliasValue = uint32Alias (1024 )
565
+ uint64AliasValue = uint64Alias (124798272 )
566
+ uintAliasValue = uintAlias (98937323493 )
567
+ float32AliasValue = float32Alias (12.5863 )
568
+ float64AliasValue = float64Alias (873983.24239 )
569
+ stringAliasValue = stringAlias ("a string with alias type" )
570
+ )
571
+
572
+ DescribeTable ("should be able to send and receive nil pointers" ,
573
+ func (value interface {}) {
574
+ result , err = session .Run ("CREATE (n {value: $value}) RETURN n.value" , map [string ]interface {}{"value" : value })
575
+ Expect (err ).To (BeNil ())
576
+
577
+ if result .Next () {
578
+ Expect (result .Record ().GetByIndex (0 )).To (BeNil ())
579
+ }
580
+ Expect (result .Next ()).To (BeFalse ())
581
+ Expect (result .Err ()).To (BeNil ())
582
+ },
583
+ Entry ("boolean" , (* booleanAlias )(nil )),
584
+ Entry ("byte" , (* byteAlias )(nil )),
585
+ Entry ("int8" , (* int8Alias )(nil )),
586
+ Entry ("int16" , (* int16Alias )(nil )),
587
+ Entry ("int32" , (* int32Alias )(nil )),
588
+ Entry ("int64" , (* int64Alias )(nil )),
589
+ Entry ("int" , (* intAlias )(nil )),
590
+ Entry ("uint8" , (* uint8Alias )(nil )),
591
+ Entry ("uint16" , (* uint16Alias )(nil )),
592
+ Entry ("uint32" , (* uint32Alias )(nil )),
593
+ Entry ("uint64" , (* uint64Alias )(nil )),
594
+ Entry ("uint" , (* uintAlias )(nil )),
595
+ Entry ("float32" , (* float32Alias )(nil )),
596
+ Entry ("float64" , (* float64Alias )(nil )),
597
+ Entry ("string" , (* stringAlias )(nil )),
598
+ Entry ("boolean array" , (* []booleanAlias )(nil )),
599
+ Entry ("byte array" , (* []byteAlias )(nil )),
600
+ Entry ("int8 array" , (* []int8Alias )(nil )),
601
+ Entry ("int16 array" , (* []int16Alias )(nil )),
602
+ Entry ("int32 array" , (* []int32Alias )(nil )),
603
+ Entry ("int64 array" , (* []int64Alias )(nil )),
604
+ Entry ("int array" , (* []intAlias )(nil )),
605
+ Entry ("uint8 array" , (* []uint8Alias )(nil )),
606
+ Entry ("uint16 array" , (* []uint16Alias )(nil )),
607
+ Entry ("uint32 array" , (* []uint32Alias )(nil )),
608
+ Entry ("uint64 array" , (* []uint64Alias )(nil )),
609
+ Entry ("uint array" , (* []uintAlias )(nil )),
610
+ Entry ("float32 array" , (* []float32Alias )(nil )),
611
+ Entry ("float64 array" , (* []float64Alias )(nil )),
612
+ Entry ("string array" , (* []stringAlias )(nil )),
613
+ Entry ("boolean array alias" , (* booleanArrayAlias )(nil )),
614
+ Entry ("byte array alias" , (* byteArrayAlias )(nil )),
615
+ Entry ("int8 array alias" , (* int8ArrayAlias )(nil )),
616
+ Entry ("int16 array alias" , (* int16ArrayAlias )(nil )),
617
+ Entry ("int32 array alias" , (* int32ArrayAlias )(nil )),
618
+ Entry ("int64 array alias" , (* int64ArrayAlias )(nil )),
619
+ Entry ("int array alias" , (* intArrayAlias )(nil )),
620
+ Entry ("uint8 array alias" , (* uint8ArrayAlias )(nil )),
621
+ Entry ("uint16 array alias" , (* uint16ArrayAlias )(nil )),
622
+ Entry ("uint32 array alias" , (* uint32ArrayAlias )(nil )),
623
+ Entry ("uint64 array alias" , (* uint64ArrayAlias )(nil )),
624
+ Entry ("uint array alias" , (* uintArrayAlias )(nil )),
625
+ Entry ("float32 array alias" , (* float32ArrayAlias )(nil )),
626
+ Entry ("float64 array alias" , (* float64ArrayAlias )(nil )),
627
+ Entry ("string array alias" , (* stringArrayAlias )(nil )),
628
+ )
629
+
630
+ DescribeTable ("should be able to send aliased types" ,
631
+ func (value interface {}, expected interface {}) {
632
+ assertEquals := func (actual interface {}) {
633
+ actualValue := reflect .ValueOf (actual )
634
+
635
+ if actualValue .Kind () == reflect .Slice {
636
+ expectedItems := make ([]interface {}, actualValue .Len ())
637
+
638
+ for i := 0 ; i < actualValue .Len (); i ++ {
639
+ expectedItems [i ] = actualValue .Index (i ).Interface ()
640
+ }
641
+
642
+ Expect (actualValue .Interface ()).Should (ConsistOf (expectedItems ... ))
643
+ } else {
644
+ Expect (actualValue .Interface ()).Should (BeEquivalentTo (expected ))
645
+ }
646
+ }
647
+
648
+ result , err = session .Run ("CREATE (n {value1: $value1, value2: $value2}) RETURN n.value1, n.value2" , map [string ]interface {}{"value1" : value , "value2" : & value })
649
+ Expect (err ).To (BeNil ())
650
+
651
+ if result .Next () {
652
+ assertEquals (result .Record ().GetByIndex (0 ))
653
+ assertEquals (result .Record ().GetByIndex (1 ))
654
+ }
655
+ Expect (result .Next ()).To (BeFalse ())
656
+ Expect (result .Err ()).To (BeNil ())
657
+ },
658
+ Entry ("boolean" , boolAliasValue , bool (boolAliasValue )),
659
+ Entry ("byte" , byteAliasValue , byte (byteAliasValue )),
660
+ Entry ("int8" , int8AliasValue , int8 (int8AliasValue )),
661
+ Entry ("int16" , int16AliasValue , int16 (int16AliasValue )),
662
+ Entry ("int32" , int32AliasValue , int32 (int32AliasValue )),
663
+ Entry ("int64" , int64AliasValue , int64 (int64AliasValue )),
664
+ Entry ("int" , intAliasValue , int (intAliasValue )),
665
+ Entry ("uint8" , uint8AliasValue , uint8 (uint8AliasValue )),
666
+ Entry ("uint16" , uint16AliasValue , uint16 (uint16AliasValue )),
667
+ Entry ("uint32" , uint32AliasValue , uint32 (uint32AliasValue )),
668
+ Entry ("uint64" , uint64AliasValue , uint64 (uint64AliasValue )),
669
+ Entry ("uint" , uintAliasValue , uint (uintAliasValue )),
670
+ Entry ("float32" , float32AliasValue , float32 (float32AliasValue )),
671
+ Entry ("float64" , float64AliasValue , float64 (float64AliasValue )),
672
+ Entry ("string" , stringAliasValue , string (stringAliasValue )),
673
+ Entry ("boolean array" , []booleanAlias {true , false }, []bool {true , false }),
674
+ Entry ("byte array" , []byteAlias {'A' , 'B' , 'C' }, []byte {'A' , 'B' , 'C' }),
675
+ Entry ("int8 array" , []int8Alias {- 5 , - 10 , 1 , 2 , 45 }, []int8 {- 5 , - 10 , 1 , 2 , 45 }),
676
+ Entry ("int16 array" , []int16Alias {- 412 , 9 , 0 , 124 }, []int16 {- 412 , 9 , 0 , 124 }),
677
+ Entry ("int32 array" , []int32Alias {- 138923 , 3123 , 2120021312 }, []int32 {- 138923 , 3123 , 2120021312 }),
678
+ Entry ("int64 array" , []int64Alias {- 1322489234 , 1239817239821 , - 1 }, []int64 {- 1322489234 , 1239817239821 , - 1 }),
679
+ Entry ("int array" , []intAlias {1123213 , - 23423442 , 83282347423 }, []int {1123213 , - 23423442 , 83282347423 }),
680
+ Entry ("uint8 array" , []uint8Alias {0 , 4 , 128 }, []uint8 {0 , 4 , 128 }),
681
+ Entry ("uint16 array" , []uint16Alias {12 , 5534 , 21333 }, []uint16 {12 , 5534 , 21333 }),
682
+ Entry ("uint32 array" , []uint32Alias {21323 , 12355343 , 3545364 }, []uint32 {21323 , 12355343 , 3545364 }),
683
+ Entry ("uint64 array" , []uint64Alias {129389 , 123 , 0 , 24294323 }, []uint64 {129389 , 123 , 0 , 24294323 }),
684
+ Entry ("uint array" , []uintAlias {12309312 , 120398213 }, []uint {12309312 , 120398213 }),
685
+ Entry ("float32 array" , []float32Alias {12.5863 , 32424.43534 }, []float32 {12.5863 , 32424.43534 }),
686
+ Entry ("float64 array" , []float64Alias {873983.24239 , 249872384.9723 }, []float64 {873983.24239 , 249872384.9723 }),
687
+ Entry ("string array" , []stringAlias {"string 1" , "string 2" }, []string {"string 1" , "string 2" }),
688
+ Entry ("boolean array alias" , booleanArrayAlias {true , false }, []bool {true , false }),
689
+ Entry ("byte array alias" , byteArrayAlias {'A' , 'B' , 'C' }, []byte {'A' , 'B' , 'C' }),
690
+ Entry ("int8 array alias" , int8ArrayAlias {- 5 , - 10 , 1 , 2 , 45 }, []int8 {- 5 , - 10 , 1 , 2 , 45 }),
691
+ Entry ("int16 array alias" , int16ArrayAlias {- 412 , 9 , 0 , 124 }, []int16 {- 412 , 9 , 0 , 124 }),
692
+ Entry ("int32 array alias" , int32ArrayAlias {- 138923 , 3123 , 2120021312 }, []int32 {- 138923 , 3123 , 2120021312 }),
693
+ Entry ("int64 array alias" , int64ArrayAlias {- 1322489234 , 1239817239821 , - 1 }, []int64 {- 1322489234 , 1239817239821 , - 1 }),
694
+ Entry ("int array alias" , intArrayAlias {1123213 , - 23423442 , 83282347423 }, []int {1123213 , - 23423442 , 83282347423 }),
695
+ Entry ("uint8 array alias" , uint8ArrayAlias {0 , 4 , 128 }, []uint8 {0 , 4 , 128 }),
696
+ Entry ("uint16 array alias" , uint16ArrayAlias {12 , 5534 , 21333 }, []uint16 {12 , 5534 , 21333 }),
697
+ Entry ("uint32 array alias" , uint32ArrayAlias {21323 , 12355343 , 3545364 }, []uint32 {21323 , 12355343 , 3545364 }),
698
+ Entry ("uint64 array alias" , uint64ArrayAlias {129389 , 123 , 0 , 24294323 }, []uint64 {129389 , 123 , 0 , 24294323 }),
699
+ Entry ("uint array alias" , uintArrayAlias {12309312 , 120398213 }, []uint {12309312 , 120398213 }),
700
+ Entry ("float32 array alias" , float32ArrayAlias {12.5863 , 32424.43534 }, []float32 {12.5863 , 32424.43534 }),
701
+ Entry ("float64 array alias" , float64ArrayAlias {873983.24239 , 249872384.9723 }, []float64 {873983.24239 , 249872384.9723 }),
702
+ Entry ("string array alias" , stringArrayAlias {"string 1" , "string 2" }, []string {"string 1" , "string 2" }),
703
+ )
704
+ })
434
705
})
0 commit comments