@@ -492,4 +492,145 @@ func TestClient(t *testing.T) {
492
492
if val != 11 {
493
493
t .Errorf ("5 + 6 == 11, but got %v" , val )
494
494
}
495
+
496
+ // Schema
497
+ schema := conn .Schema
498
+ if schema .Spaces == nil {
499
+ t .Errorf ("schema.Spaces is nil" )
500
+ }
501
+ if schema .SpacesN == nil {
502
+ t .Errorf ("schema.SpacesN is nil" )
503
+ }
504
+ var space , space2 * Space
505
+ var ok bool
506
+ if space , ok = schema .Spaces [9991 ]; ! ok {
507
+ t .Errorf ("space with id = 9991 was not found in schema.Spaces" )
508
+ }
509
+ if space2 , ok = schema .SpacesN ["schematest" ]; ! ok {
510
+ t .Errorf ("space with name 'schematest' was not found in schema.Spaces" )
511
+ }
512
+ if space != space2 {
513
+ t .Errorf ("space with id = 9991 and space with name schematest are different" )
514
+ }
515
+ if space .Id != 9991 {
516
+ t .Errorf ("space 9991 has incorrect Id" )
517
+ }
518
+ if space .Name != "schematest" {
519
+ t .Errorf ("space 9991 has incorrect Name" )
520
+ }
521
+ if ! space .Temporary {
522
+ t .Errorf ("space 9991 should be temporary" )
523
+ }
524
+ if space .Engine != "memtx" {
525
+ t .Errorf ("space 9991 engine should be memtx" )
526
+ }
527
+ if space .FieldsCount != 7 {
528
+ t .Errorf ("space 9991 has incorrect fields count" )
529
+ }
530
+
531
+ if space .Fields == nil {
532
+ t .Errorf ("space.Fields is nill" )
533
+ }
534
+ if space .FieldsN == nil {
535
+ t .Errorf ("space.FieldsN is nill" )
536
+ }
537
+ if len (space .Fields ) != 3 {
538
+ t .Errorf ("space.Fields len is incorrect" )
539
+ }
540
+ if len (space .FieldsN ) != 2 {
541
+ t .Errorf ("space.FieldsN len is incorrect" )
542
+ }
543
+
544
+ var field1 , field2 , field5 , field1_ , field5_ * Field
545
+ if field1 , ok = space .Fields [1 ]; ! ok {
546
+ t .Errorf ("field id = 1 was not found" )
547
+ }
548
+ if field2 , ok = space .Fields [2 ]; ! ok {
549
+ t .Errorf ("field id = 2 was not found" )
550
+ }
551
+ if field5 , ok = space .Fields [5 ]; ! ok {
552
+ t .Errorf ("field id = 5 was not found" )
553
+ }
554
+
555
+ if field1_ , ok = space .FieldsN ["name1" ]; ! ok {
556
+ t .Errorf ("field name = name1 was not found" )
557
+ }
558
+ if field5_ , ok = space .FieldsN ["name5" ]; ! ok {
559
+ t .Errorf ("field name = name5 was not found" )
560
+ }
561
+ if field1 != field1_ || field5 != field5_ {
562
+ t .Errorf ("field with id = 1 and field with name 'name1' are different" )
563
+ }
564
+ if field1 .Name != "name1" {
565
+ t .Errorf ("field 1 has incorrect Name" )
566
+ }
567
+ if field1 .Type != "" {
568
+ t .Errorf ("field 1 has incorrect Type" )
569
+ }
570
+ if field2 .Name != "" {
571
+ t .Errorf ("field 2 has incorrect Name" )
572
+ }
573
+ if field2 .Type != "type2" {
574
+ t .Errorf ("field 2 has incorrect Type" )
575
+ }
576
+
577
+ if space .Indexes == nil {
578
+ t .Errorf ("space.Indexes is nill" )
579
+ }
580
+ if space .IndexesN == nil {
581
+ t .Errorf ("space.IndexesN is nill" )
582
+ }
583
+ if len (space .Indexes ) != 2 {
584
+ t .Errorf ("space.Indexes len is incorrect" )
585
+ }
586
+ if len (space .IndexesN ) != 2 {
587
+ t .Errorf ("space.IndexesN len is incorrect" )
588
+ }
589
+
590
+ var index0 , index3 , index0_ , index3_ * Index
591
+ if index0 , ok = space .Indexes [0 ]; ! ok {
592
+ t .Errorf ("index id = 0 was not found" )
593
+ }
594
+ if index3 , ok = space .Indexes [3 ]; ! ok {
595
+ t .Errorf ("index id = 3 was not found" )
596
+ }
597
+ if index0_ , ok = space .IndexesN ["primary" ]; ! ok {
598
+ t .Errorf ("index name = primary was not found" )
599
+ }
600
+ if index3_ , ok = space .IndexesN ["secondary" ]; ! ok {
601
+ t .Errorf ("index name = secondary was not found" )
602
+ }
603
+ if index0 != index0_ || index3 != index3_ {
604
+ t .Errorf ("index with id = 3 and index with name 'secondary' are different" )
605
+ }
606
+ if index3 .Id != 3 {
607
+ t .Errorf ("index has incorrect Id" )
608
+ }
609
+ if index0 .Name != "primary" {
610
+ t .Errorf ("index has incorrect Name" )
611
+ }
612
+ if index0 .Type != "hash" || index3 .Type != "tree" {
613
+ t .Errorf ("index has incorrect Type" )
614
+ }
615
+ if ! index0 .Unique || index3 .Unique {
616
+ t .Errorf ("index has incorrect Unique" )
617
+ }
618
+ if index3 .Fields == nil {
619
+ t .Errorf ("index.Fields is nil" )
620
+ }
621
+ if len (index3 .Fields ) != 2 {
622
+ t .Errorf ("index.Fields len is incorrect" )
623
+ }
624
+
625
+ ifield1 := index3 .Fields [0 ]
626
+ ifield2 := index3 .Fields [1 ]
627
+ if ifield1 == nil || ifield2 == nil {
628
+ t .Errorf ("index field is nil" )
629
+ }
630
+ if ifield1 .Id != 1 || ifield2 .Id != 2 {
631
+ t .Errorf ("index field has incorrect Id" )
632
+ }
633
+ if ifield1 .Type != "num" || ifield2 .Type != "STR" {
634
+ t .Errorf ("index field has incorrect Type[" )
635
+ }
495
636
}
0 commit comments