@@ -141,6 +141,7 @@ var _ = Describe("CatalogSource Controller Test", func() {
141141 By ("running re-reconcile" )
142142 res , err = reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
143143 Expect (res ).To (Equal (ctrl.Result {}))
144+ Expect (err ).ToNot (HaveOccurred ())
144145
145146 By ("checking the cache is empty again" )
146147 entities = nil
@@ -151,5 +152,63 @@ var _ = Describe("CatalogSource Controller Test", func() {
151152 Expect (err ).ToNot (HaveOccurred ())
152153 Expect (entities ).To (BeEmpty ())
153154 })
155+
156+ Describe ("querying CatalogSource EntitySource" , func () {
157+ BeforeEach (func () {
158+ registryEntities := []* input.Entity {
159+ input .NewEntity (deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.1.0" , catalogSourceName , namespace )), map [string ]string {}),
160+ input .NewEntity (deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.2.0" , catalogSourceName , namespace )), map [string ]string {"k" : "v" }),
161+ }
162+ fakeRegistry .setEntitiesForSource (opKey .String (), registryEntities ... )
163+
164+ res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : opKey })
165+ Expect (err ).ToNot (HaveOccurred ())
166+ Expect (res ).To (Equal (ctrl.Result {}))
167+ })
168+ Describe ("Get" , func () {
169+ It ("should fetch an entity by ID" , func () {
170+ Expect (reconciler .Get (ctx , deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.1.0" , catalogSourceName , namespace )))).To (
171+ Equal (input .NewEntity (deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.1.0" , catalogSourceName , namespace )), map [string ]string {})),
172+ )
173+ })
174+ It ("should not fetch anything for nonexistent entity ID" , func () {
175+ Expect (reconciler .Get (ctx , "non-existent" )).To (BeNil ())
176+ })
177+ })
178+ Describe ("Filter" , func () {
179+ It ("should return entities that meet filter predicates" , func () {
180+ actual , err := reconciler .Filter (ctx , func (e * input.Entity ) bool {
181+ _ , ok := e .Properties ["k" ]
182+ return ok
183+ })
184+ Expect (err ).ToNot (HaveOccurred ())
185+ Expect (actual ).To (ConsistOf (input.EntityList {* input .NewEntity (deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.2.0" , catalogSourceName , namespace )), map [string ]string {"k" : "v" })}))
186+ })
187+ })
188+ Describe ("GroupBy" , func () {
189+ It ("should group entities by the keys provided by the groupBy function" , func () {
190+ actual , err := reconciler .GroupBy (ctx , func (e * input.Entity ) []string {
191+ var keys []string
192+ for k := range e .Properties {
193+ keys = append (keys , k )
194+ }
195+ return keys
196+ })
197+ Expect (err ).ToNot (HaveOccurred ())
198+ Expect (actual ).To (Equal (input.EntityListMap {"k" : input.EntityList {* input .NewEntity (deppy .Identifier (fmt .Sprintf ("%s/%s/pkg1/chan1/0.2.0" , catalogSourceName , namespace )), map [string ]string {"k" : "v" })}}))
199+ })
200+ })
201+ Describe ("Iterate" , func () {
202+ It ("should go through all entities" , func () {
203+ var ids []string
204+ Expect (reconciler .Iterate (ctx , func (e * input.Entity ) error {
205+ ids = append (ids , e .Identifier ().String ())
206+ return nil
207+ })).To (BeNil ())
208+ Expect (ids ).To (ConsistOf ([]string {fmt .Sprintf ("%s/%s/pkg1/chan1/0.1.0" , catalogSourceName , namespace ),
209+ fmt .Sprintf ("%s/%s/pkg1/chan1/0.2.0" , catalogSourceName , namespace )}))
210+ })
211+ })
212+ })
154213 })
155214})
0 commit comments