@@ -52,6 +52,34 @@ func (m *Member) decodeMsgpackImpl(d *Decoder) error {
52
52
return nil
53
53
}
54
54
55
+ func convertUint64 (v interface {}) (result uint64 , err error ) {
56
+ switch v := v .(type ) {
57
+ case uint :
58
+ result = uint64 (v )
59
+ case uint8 :
60
+ result = uint64 (v )
61
+ case uint16 :
62
+ result = uint64 (v )
63
+ case uint32 :
64
+ result = uint64 (v )
65
+ case uint64 :
66
+ result = uint64 (v )
67
+ case int :
68
+ result = uint64 (v )
69
+ case int8 :
70
+ result = uint64 (v )
71
+ case int16 :
72
+ result = uint64 (v )
73
+ case int32 :
74
+ result = uint64 (v )
75
+ case int64 :
76
+ result = uint64 (v )
77
+ default :
78
+ err = fmt .Errorf ("Non-number value %T" , v )
79
+ }
80
+ return
81
+ }
82
+
55
83
var server = "127.0.0.1:3013"
56
84
var spaceNo = uint32 (517 )
57
85
var spaceName = "test"
@@ -524,7 +552,7 @@ func TestClient(t *testing.T) {
524
552
if len (tpl ) != 3 {
525
553
t .Errorf ("Unexpected body of Insert (tuple len)" )
526
554
}
527
- if id , ok := tpl [0 ].( uint64 ); ! ok || id != 1 {
555
+ if id , err := convertUint64 ( tpl [0 ]); err != nil || id != 1 {
528
556
t .Errorf ("Unexpected body of Insert (0)" )
529
557
}
530
558
if h , ok := tpl [1 ].(string ); ! ok || h != "hello" {
@@ -557,7 +585,7 @@ func TestClient(t *testing.T) {
557
585
if len (tpl ) != 3 {
558
586
t .Errorf ("Unexpected body of Delete (tuple len)" )
559
587
}
560
- if id , ok := tpl [0 ].( uint64 ); ! ok || id != 1 {
588
+ if id , err := convertUint64 ( tpl [0 ]); err != nil || id != 1 {
561
589
t .Errorf ("Unexpected body of Delete (0)" )
562
590
}
563
591
if h , ok := tpl [1 ].(string ); ! ok || h != "hello" {
@@ -599,7 +627,7 @@ func TestClient(t *testing.T) {
599
627
if len (tpl ) != 3 {
600
628
t .Errorf ("Unexpected body of Replace (tuple len)" )
601
629
}
602
- if id , ok := tpl [0 ].( uint64 ); ! ok || id != 2 {
630
+ if id , err := convertUint64 ( tpl [0 ]); err != nil || id != 2 {
603
631
t .Errorf ("Unexpected body of Replace (0)" )
604
632
}
605
633
if h , ok := tpl [1 ].(string ); ! ok || h != "hi" {
@@ -624,7 +652,7 @@ func TestClient(t *testing.T) {
624
652
if len (tpl ) != 2 {
625
653
t .Errorf ("Unexpected body of Update (tuple len)" )
626
654
}
627
- if id , ok := tpl [0 ].( uint64 ); ! ok || id != 2 {
655
+ if id , err := convertUint64 ( tpl [0 ]); err != nil || id != 2 {
628
656
t .Errorf ("Unexpected body of Update (0)" )
629
657
}
630
658
if h , ok := tpl [1 ].(string ); ! ok || h != "bye" {
@@ -673,7 +701,7 @@ func TestClient(t *testing.T) {
673
701
if tpl , ok := resp .Data [0 ].([]interface {}); ! ok {
674
702
t .Errorf ("Unexpected body of Select" )
675
703
} else {
676
- if id , ok := tpl [0 ].( uint64 ); ! ok || id != 10 {
704
+ if id , err := convertUint64 ( tpl [0 ]); err != nil || id != 10 {
677
705
t .Errorf ("Unexpected body of Select (0)" )
678
706
}
679
707
if h , ok := tpl [1 ].(string ); ! ok || h != "val 10" {
@@ -768,15 +796,15 @@ func TestClient(t *testing.T) {
768
796
if err != nil {
769
797
t .Errorf ("Failed to use Call" )
770
798
}
771
- if resp .Data [0 ].([]interface {})[0 ].( uint64 ) != 2 {
799
+ if val , err := convertUint64 ( resp .Data [0 ].([]interface {})[0 ]); err != nil || val != 2 {
772
800
t .Errorf ("result is not {{1}} : %v" , resp .Data )
773
801
}
774
802
775
803
resp , err = conn .Call17 ("simple_incr" , []interface {}{1 })
776
804
if err != nil {
777
805
t .Errorf ("Failed to use Call17" )
778
806
}
779
- if resp .Data [0 ].( uint64 ) != 2 {
807
+ if val , err := convertUint64 ( resp .Data [0 ]); err != nil || val != 2 {
780
808
t .Errorf ("result is not {{1}} : %v" , resp .Data )
781
809
}
782
810
@@ -791,8 +819,7 @@ func TestClient(t *testing.T) {
791
819
if len (resp .Data ) < 1 {
792
820
t .Errorf ("Response.Data is empty after Eval" )
793
821
}
794
- val := resp .Data [0 ].(uint64 )
795
- if val != 11 {
822
+ if val , err := convertUint64 (resp .Data [0 ]); err != nil || val != 11 {
796
823
t .Errorf ("5 + 6 == 11, but got %v" , val )
797
824
}
798
825
}
@@ -984,7 +1011,18 @@ func TestSQL(t *testing.T) {
984
1011
assert .NoError (t , err , "Failed to Execute, Query number: %d" , i )
985
1012
assert .NotNil (t , resp , "Response is nil after Execute\n Query number: %d" , i )
986
1013
for j := range resp .Data {
987
- assert .Equal (t , resp .Data [j ], test .Resp .Data [j ], "Response data is wrong" )
1014
+ fixed := make ([]interface {}, 0 )
1015
+
1016
+ assert .EqualValues (t , reflect .TypeOf (resp .Data [j ]).Kind (), reflect .Slice )
1017
+ s := reflect .ValueOf (resp .Data [j ])
1018
+ for k := 0 ; k < s .Len (); k ++ {
1019
+ val := s .Index (k )
1020
+ if num , err := convertUint64 (val .Interface ()); err == nil {
1021
+ val = reflect .ValueOf (num )
1022
+ }
1023
+ fixed = append (fixed , val .Interface ())
1024
+ }
1025
+ assert .Equal (t , fixed , test .Resp .Data [j ], "Response data is wrong" )
988
1026
}
989
1027
assert .Equal (t , resp .SQLInfo .AffectedCount , test .Resp .SQLInfo .AffectedCount , "Affected count is wrong" )
990
1028
0 commit comments