@@ -21,6 +21,7 @@ import (
2121 . "github.com/onsi/ginkgo/v2"
2222 . "github.com/onsi/gomega"
2323 . "github.com/onsi/gomega/gstruct"
24+
2425 gomega_types "github.com/onsi/gomega/types"
2526 corev1 "k8s.io/api/core/v1"
2627 k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -37,7 +38,6 @@ var _ = Describe("ServiceInstanceRepository", func() {
3738 korifiv1alpha1.CFServiceInstanceList ,
3839 * korifiv1alpha1.CFServiceInstanceList ,
3940 ]
40- sorter * fake.ServiceInstanceSorter
4141
4242 org * korifiv1alpha1.CFOrg
4343 space * korifiv1alpha1.CFSpace
@@ -50,15 +50,10 @@ var _ = Describe("ServiceInstanceRepository", func() {
5050 korifiv1alpha1.CFServiceInstanceList ,
5151 * korifiv1alpha1.CFServiceInstanceList ,
5252 ]{}
53- sorter = new (fake.ServiceInstanceSorter )
54- sorter .SortStub = func (records []repositories.ServiceInstanceRecord , _ string ) []repositories.ServiceInstanceRecord {
55- return records
56- }
5753
5854 serviceInstanceRepo = repositories .NewServiceInstanceRepo (
5955 spaceScopedKlient ,
6056 conditionAwaiter ,
61- sorter ,
6257 rootNamespace ,
6358 )
6459
@@ -716,7 +711,7 @@ var _ = Describe("ServiceInstanceRepository", func() {
716711 }
717712 Expect (k8sClient .Create (ctx , cfServiceInstance1 )).To (Succeed ())
718713
719- filters = repositories.ListServiceInstanceMessage {OrderBy : "foo " }
714+ filters = repositories.ListServiceInstanceMessage {OrderBy : "name " }
720715 })
721716
722717 JustBeforeEach (func () {
@@ -740,35 +735,43 @@ var _ = Describe("ServiceInstanceRepository", func() {
740735 ))
741736 })
742737
743- It ("sort the service instances" , func () {
744- Expect (sorter .SortCallCount ()).To (Equal (1 ))
745- sortedServiceInstances , field := sorter .SortArgsForCall (0 )
746- Expect (field ).To (Equal ("foo" ))
747- Expect (sortedServiceInstances ).To (ConsistOf (
748- MatchFields (IgnoreExtras , Fields {"GUID" : Equal (cfServiceInstance1 .Name )}),
749- ))
750- })
738+ DescribeTable ("ordering" ,
739+ func (msg repositories.ListServiceInstanceMessage , match gomega_types.GomegaMatcher ) {
740+ fakeKlient := new (fake.Klient )
741+ instancesRepo := repositories .NewServiceInstanceRepo (fakeKlient , conditionAwaiter , rootNamespace )
742+
743+ _ , err := instancesRepo .ListServiceInstances (ctx , authInfo , msg )
744+ Expect (err ).NotTo (HaveOccurred ())
751745
752- Describe ("filtering" , func () {
746+ Expect (fakeKlient .ListCallCount ()).To (Equal (1 ))
747+ _ , _ , listOptions := fakeKlient .ListArgsForCall (0 )
748+ Expect (listOptions ).To (match )
749+ },
750+ Entry ("name" , repositories.ListServiceInstanceMessage {OrderBy : "name" }, ContainElement (repositories.SortOpt {By : "Display Name" , Desc : false })),
751+ Entry ("-name" , repositories.ListServiceInstanceMessage {OrderBy : "-name" }, ContainElement (repositories.SortOpt {By : "Display Name" , Desc : true })),
752+ )
753+
754+ Describe ("list options" , func () {
753755 var fakeKlient * fake.Klient
754756
755757 BeforeEach (func () {
756758 fakeKlient = new (fake.Klient )
757- serviceInstanceRepo = repositories .NewServiceInstanceRepo (fakeKlient , conditionAwaiter , sorter , rootNamespace )
759+ serviceInstanceRepo = repositories .NewServiceInstanceRepo (fakeKlient , conditionAwaiter , rootNamespace )
758760 filters = repositories.ListServiceInstanceMessage {
759761 Names : []string {"instance-1" , "instance-2" },
760762 SpaceGUIDs : []string {"space-guid-1" , "space-guid-2" },
761763 GUIDs : []string {"guid-1" , "guid-2" },
762764 LabelSelector : "a-label=a-label-value" ,
763765 PlanGUIDs : []string {"plan-guid-1" , "plan-guid-2" },
766+ OrderBy : "updated_at" ,
764767 Pagination : repositories.Pagination {
765768 PerPage : 1 ,
766769 Page : 10 ,
767770 },
768771 }
769772 })
770773
771- It ("translates filter parameters to klient list options" , func () {
774+ It ("translates parameters to klient list options" , func () {
772775 Expect (fakeKlient .ListCallCount ()).To (Equal (1 ))
773776 _ , _ , listOptions := fakeKlient .ListArgsForCall (0 )
774777 Expect (listOptions ).To (ConsistOf (
@@ -777,6 +780,7 @@ var _ = Describe("ServiceInstanceRepository", func() {
777780 repositories .WithLabelIn (korifiv1alpha1 .GUIDLabelKey , []string {"guid-1" , "guid-2" }),
778781 repositories .WithLabelSelector ("a-label=a-label-value" ),
779782 repositories .WithLabelIn (korifiv1alpha1 .PlanGUIDLabelKey , []string {"plan-guid-1" , "plan-guid-2" }),
783+ repositories .WithOrdering ("updated_at" ),
780784 repositories .WithPaging (repositories.Pagination {
781785 PerPage : 1 ,
782786 Page : 10 ,
@@ -1077,45 +1081,3 @@ var _ = Describe("ServiceInstanceRepository", func() {
10771081 })
10781082 })
10791083})
1080-
1081- var _ = DescribeTable ("ServiceInstanceSorter" ,
1082- func (s1 , s2 repositories.ServiceInstanceRecord , field string , match gomega_types.GomegaMatcher ) {
1083- Expect (repositories .ServiceInstanceComparator (field )(s1 , s2 )).To (match )
1084- },
1085- Entry ("created_at" ,
1086- repositories.ServiceInstanceRecord {CreatedAt : time .UnixMilli (1 )},
1087- repositories.ServiceInstanceRecord {CreatedAt : time .UnixMilli (2 )},
1088- "created_at" ,
1089- BeNumerically ("<" , 0 ),
1090- ),
1091- Entry ("-created_at" ,
1092- repositories.ServiceInstanceRecord {CreatedAt : time .UnixMilli (1 )},
1093- repositories.ServiceInstanceRecord {CreatedAt : time .UnixMilli (2 )},
1094- "-created_at" ,
1095- BeNumerically (">" , 0 ),
1096- ),
1097- Entry ("updated_at" ,
1098- repositories.ServiceInstanceRecord {UpdatedAt : tools .PtrTo (time .UnixMilli (1 ))},
1099- repositories.ServiceInstanceRecord {UpdatedAt : tools .PtrTo (time .UnixMilli (2 ))},
1100- "updated_at" ,
1101- BeNumerically ("<" , 0 ),
1102- ),
1103- Entry ("-updated_at" ,
1104- repositories.ServiceInstanceRecord {UpdatedAt : tools .PtrTo (time .UnixMilli (1 ))},
1105- repositories.ServiceInstanceRecord {UpdatedAt : tools .PtrTo (time .UnixMilli (2 ))},
1106- "-updated_at" ,
1107- BeNumerically (">" , 0 ),
1108- ),
1109- Entry ("name" ,
1110- repositories.ServiceInstanceRecord {Name : "first-instance" },
1111- repositories.ServiceInstanceRecord {Name : "second-instance" },
1112- "name" ,
1113- BeNumerically ("<" , 0 ),
1114- ),
1115- Entry ("-name" ,
1116- repositories.ServiceInstanceRecord {Name : "first-instance" },
1117- repositories.ServiceInstanceRecord {Name : "second-instance" },
1118- "-name" ,
1119- BeNumerically (">" , 0 ),
1120- ),
1121- )
0 commit comments