@@ -16,6 +16,7 @@ package metautils_test
16
16
17
17
import (
18
18
"reflect"
19
+ "strings"
19
20
20
21
"github.com/golang/mock/gomock"
21
22
. "github.com/onmetal/controller-utils/metautils"
@@ -555,4 +556,28 @@ var _ = Describe("Metautils", func() {
555
556
Entry ("other keys present" , map [string ]string {"bar" : "baz" }, map [string ]string {"foo" : "bar" }, map [string ]string {"bar" : "baz" , "foo" : "bar" }),
556
557
Entry ("partial other keys, same key" , map [string ]string {"foo" : "baz" , "bar" : "baz" }, map [string ]string {"foo" : "bar" }, map [string ]string {"foo" : "bar" , "bar" : "baz" }),
557
558
)
559
+
560
+ Describe ("FilterList" , func () {
561
+ It ("should filter the list with the given function" , func () {
562
+ list := & corev1.SecretList {
563
+ Items : []corev1.Secret {
564
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "foo" , Name : "bar" }},
565
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "foo" , Name : "baz" }},
566
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "foo" , Name : "qux" }},
567
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "bar" , Name : "bar" }},
568
+ },
569
+ }
570
+
571
+ Expect (FilterList (list , func (obj client.Object ) bool {
572
+ return obj .GetNamespace () == "foo" && strings .HasPrefix (obj .GetName (), "b" )
573
+ })).To (Succeed ())
574
+
575
+ Expect (list ).To (Equal (& corev1.SecretList {
576
+ Items : []corev1.Secret {
577
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "foo" , Name : "bar" }},
578
+ {ObjectMeta : metav1.ObjectMeta {Namespace : "foo" , Name : "baz" }},
579
+ },
580
+ }))
581
+ })
582
+ })
558
583
})
0 commit comments