@@ -630,30 +630,34 @@ func (st *StoreTest) TestEntitySearch(t *T) {
630
630
}
631
631
632
632
func (st * StoreTest ) TestEntitySearchPagination (t * T ) {
633
+ store .SetPaginationDefaults (store.PaginationDefaults {
634
+ DefaultLimit : 7 ,
635
+ })
636
+
633
637
var users []* ttnpb.User
634
- for i := 0 ; i < 7 ; i ++ {
638
+ for i := 0 ; i < 15 ; i ++ {
635
639
users = append (users , st .population .NewUser ())
636
640
}
637
641
638
642
var applications []* ttnpb.Application
639
- for i := 0 ; i < 7 ; i ++ {
643
+ for i := 0 ; i < 15 ; i ++ {
640
644
applications = append (applications , st .population .NewApplication (users [0 ].GetOrganizationOrUserIdentifiers ()))
641
645
}
642
646
var clients []* ttnpb.Client
643
- for i := 0 ; i < 7 ; i ++ {
647
+ for i := 0 ; i < 15 ; i ++ {
644
648
clients = append (clients , st .population .NewClient (users [0 ].GetOrganizationOrUserIdentifiers ()))
645
649
}
646
650
var gateways []* ttnpb.Gateway
647
- for i := 0 ; i < 7 ; i ++ {
651
+ for i := 0 ; i < 15 ; i ++ {
648
652
gateways = append (gateways , st .population .NewGateway (users [0 ].GetOrganizationOrUserIdentifiers ()))
649
653
}
650
654
var organizations []* ttnpb.Organization
651
- for i := 0 ; i < 7 ; i ++ {
655
+ for i := 0 ; i < 15 ; i ++ {
652
656
organizations = append (organizations , st .population .NewOrganization (users [0 ].GetOrganizationOrUserIdentifiers ()))
653
657
}
654
658
655
659
var endDevices []* ttnpb.EndDevice
656
- for i := 0 ; i < 7 ; i ++ {
660
+ for i := 0 ; i < 15 ; i ++ {
657
661
endDevices = append (endDevices , st .population .NewEndDevice (applications [0 ].GetIds ()))
658
662
}
659
663
@@ -676,17 +680,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
676
680
677
681
got , err := s .SearchApplications (paginateCtx , nil , & ttnpb.SearchApplicationsRequest {})
678
682
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
679
- if page == 4 {
680
- a .So (got , should .HaveLength , 1 )
681
- } else {
682
- a .So (got , should .HaveLength , 2 )
683
- }
683
+ a .So (got , should .HaveLength , 2 )
684
684
for i , e := range got {
685
685
a .So (e , should .Resemble , applications [i + 2 * int (page - 1 )].Ids )
686
686
}
687
687
}
688
688
689
- a .So (total , should .Equal , 7 )
689
+ a .So (total , should .Equal , 15 )
690
+ }
691
+ })
692
+
693
+ t .Run ("Applications_PageLimit" , func (t * T ) {
694
+ a , ctx := test .New (t )
695
+
696
+ var total uint64
697
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
698
+ got , err := s .SearchApplications (paginateCtx , nil , & ttnpb.SearchApplicationsRequest {})
699
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
700
+ a .So (got , should .HaveLength , 7 )
701
+ }
702
+
703
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
704
+ got , err = s .SearchApplications (paginateCtx , nil , & ttnpb.SearchApplicationsRequest {})
705
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
706
+ a .So (got , should .HaveLength , 7 )
690
707
}
691
708
})
692
709
@@ -699,17 +716,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
699
716
700
717
got , err := s .SearchClients (paginateCtx , nil , & ttnpb.SearchClientsRequest {})
701
718
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
702
- if page == 4 {
703
- a .So (got , should .HaveLength , 1 )
704
- } else {
705
- a .So (got , should .HaveLength , 2 )
706
- }
719
+ a .So (got , should .HaveLength , 2 )
707
720
for i , e := range got {
708
721
a .So (e , should .Resemble , clients [i + 2 * int (page - 1 )].Ids )
709
722
}
710
723
}
711
724
712
- a .So (total , should .Equal , 7 )
725
+ a .So (total , should .Equal , 15 )
726
+ }
727
+ })
728
+
729
+ t .Run ("Clients_PageLimit" , func (t * T ) {
730
+ a , ctx := test .New (t )
731
+
732
+ var total uint64
733
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
734
+ got , err := s .SearchClients (paginateCtx , nil , & ttnpb.SearchClientsRequest {})
735
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
736
+ a .So (got , should .HaveLength , 7 )
737
+ }
738
+
739
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
740
+ got , err = s .SearchClients (paginateCtx , nil , & ttnpb.SearchClientsRequest {})
741
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
742
+ a .So (got , should .HaveLength , 7 )
713
743
}
714
744
})
715
745
@@ -724,17 +754,34 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
724
754
ApplicationIds : applications [0 ].GetIds (),
725
755
})
726
756
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
727
- if page == 4 {
728
- a .So (got , should .HaveLength , 1 )
729
- } else {
730
- a .So (got , should .HaveLength , 2 )
731
- }
757
+ a .So (got , should .HaveLength , 2 )
732
758
for i , e := range got {
733
759
a .So (e , should .Resemble , endDevices [i + 2 * int (page - 1 )].Ids )
734
760
}
735
761
}
736
762
737
- a .So (total , should .Equal , 7 )
763
+ a .So (total , should .Equal , 15 )
764
+ }
765
+ })
766
+
767
+ t .Run ("EndDevices_PageLimit" , func (t * T ) {
768
+ a , ctx := test .New (t )
769
+
770
+ var total uint64
771
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
772
+ got , err := s .SearchEndDevices (paginateCtx , & ttnpb.SearchEndDevicesRequest {
773
+ ApplicationIds : applications [0 ].GetIds (),
774
+ })
775
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
776
+ a .So (got , should .HaveLength , 7 )
777
+ }
778
+
779
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
780
+ got , err = s .SearchEndDevices (paginateCtx , & ttnpb.SearchEndDevicesRequest {
781
+ ApplicationIds : applications [0 ].GetIds (),
782
+ })
783
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
784
+ a .So (got , should .HaveLength , 7 )
738
785
}
739
786
})
740
787
@@ -747,17 +794,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
747
794
748
795
got , err := s .SearchGateways (paginateCtx , nil , & ttnpb.SearchGatewaysRequest {})
749
796
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
750
- if page == 4 {
751
- a .So (got , should .HaveLength , 1 )
752
- } else {
753
- a .So (got , should .HaveLength , 2 )
754
- }
797
+ a .So (got , should .HaveLength , 2 )
755
798
for i , e := range got {
756
799
a .So (e , should .Resemble , gateways [i + 2 * int (page - 1 )].Ids )
757
800
}
758
801
}
759
802
760
- a .So (total , should .Equal , 7 )
803
+ a .So (total , should .Equal , 15 )
804
+ }
805
+ })
806
+
807
+ t .Run ("Gateways_PageLimit" , func (t * T ) {
808
+ a , ctx := test .New (t )
809
+
810
+ var total uint64
811
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
812
+ got , err := s .SearchGateways (paginateCtx , nil , & ttnpb.SearchGatewaysRequest {})
813
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
814
+ a .So (got , should .HaveLength , 7 )
815
+ }
816
+
817
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
818
+ got , err = s .SearchGateways (paginateCtx , nil , & ttnpb.SearchGatewaysRequest {})
819
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
820
+ a .So (got , should .HaveLength , 7 )
761
821
}
762
822
})
763
823
@@ -770,17 +830,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
770
830
771
831
got , err := s .SearchOrganizations (paginateCtx , nil , & ttnpb.SearchOrganizationsRequest {})
772
832
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
773
- if page == 4 {
774
- a .So (got , should .HaveLength , 1 )
775
- } else {
776
- a .So (got , should .HaveLength , 2 )
777
- }
833
+ a .So (got , should .HaveLength , 2 )
778
834
for i , e := range got {
779
835
a .So (e , should .Resemble , organizations [i + 2 * int (page - 1 )].Ids )
780
836
}
781
837
}
782
838
783
- a .So (total , should .Equal , 7 )
839
+ a .So (total , should .Equal , 15 )
840
+ }
841
+ })
842
+
843
+ t .Run ("Organizations_PageLimit" , func (t * T ) {
844
+ a , ctx := test .New (t )
845
+
846
+ var total uint64
847
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
848
+ got , err := s .SearchOrganizations (paginateCtx , nil , & ttnpb.SearchOrganizationsRequest {})
849
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
850
+ a .So (got , should .HaveLength , 7 )
851
+ }
852
+
853
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
854
+ got , err = s .SearchOrganizations (paginateCtx , nil , & ttnpb.SearchOrganizationsRequest {})
855
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
856
+ a .So (got , should .HaveLength , 7 )
784
857
}
785
858
})
786
859
@@ -793,17 +866,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
793
866
794
867
got , err := s .SearchUsers (paginateCtx , & ttnpb.SearchUsersRequest {})
795
868
if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
796
- if page == 4 {
797
- a .So (got , should .HaveLength , 1 )
798
- } else {
799
- a .So (got , should .HaveLength , 2 )
800
- }
869
+ a .So (got , should .HaveLength , 2 )
801
870
for i , e := range got {
802
871
a .So (e , should .Resemble , users [i + 2 * int (page - 1 )].Ids )
803
872
}
804
873
}
805
874
806
- a .So (total , should .Equal , 7 )
875
+ a .So (total , should .Equal , 15 )
876
+ }
877
+ })
878
+
879
+ t .Run ("Users_PageLimit" , func (t * T ) {
880
+ a , ctx := test .New (t )
881
+
882
+ var total uint64
883
+ paginateCtx := store .WithPagination (ctx , 0 , 0 , & total )
884
+ got , err := s .SearchUsers (paginateCtx , & ttnpb.SearchUsersRequest {})
885
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
886
+ a .So (got , should .HaveLength , 7 )
887
+ }
888
+
889
+ paginateCtx = store .WithPagination (ctx , 0 , 2 , & total )
890
+ got , err = s .SearchUsers (paginateCtx , & ttnpb.SearchUsersRequest {})
891
+ if a .So (err , should .BeNil ) && a .So (got , should .NotBeNil ) {
892
+ a .So (got , should .HaveLength , 7 )
807
893
}
808
894
})
809
895
}
0 commit comments