@@ -1573,6 +1573,85 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, compaction Co
1573
1573
}
1574
1574
}
1575
1575
1576
+ // RunTestGetListRecursivePrefix tests how recursive parameter works for object keys that are prefixes of each other.
1577
+ func RunTestGetListRecursivePrefix (ctx context.Context , t * testing.T , store storage.Interface ) {
1578
+ fooKey , fooObj := testPropagateStore (ctx , t , store , & example.Pod {ObjectMeta : metav1.ObjectMeta {Name : "foo" , Namespace : "test-ns" }})
1579
+ fooBarKey , fooBarObj := testPropagateStore (ctx , t , store , & example.Pod {ObjectMeta : metav1.ObjectMeta {Name : "foobar" , Namespace : "test-ns" }})
1580
+ _ , otherNamespaceObj := testPropagateStore (ctx , t , store , & example.Pod {ObjectMeta : metav1.ObjectMeta {Name : "baz" , Namespace : "test-ns2" }})
1581
+
1582
+ tests := []struct {
1583
+ name string
1584
+ key string
1585
+ recursive bool
1586
+ expectedOut []example.Pod
1587
+ }{
1588
+ {
1589
+ name : "NonRecursive on resource prefix doesn't return any objects" ,
1590
+ key : "/pods/" ,
1591
+ recursive : false ,
1592
+ expectedOut : []example.Pod {},
1593
+ },
1594
+ {
1595
+ name : "Recursive on resource prefix returns all objects" ,
1596
+ key : "/pods/" ,
1597
+ recursive : true ,
1598
+ expectedOut : []example.Pod {* fooObj , * fooBarObj , * otherNamespaceObj },
1599
+ },
1600
+ {
1601
+ name : "NonRecursive on namespace prefix doesn't return any objects" ,
1602
+ key : "/pods/test-ns/" ,
1603
+ recursive : false ,
1604
+ expectedOut : []example.Pod {},
1605
+ },
1606
+ {
1607
+ name : "Recursive on resource prefix returns objects in the namespace" ,
1608
+ key : "/pods/test-ns/" ,
1609
+ recursive : true ,
1610
+ expectedOut : []example.Pod {* fooObj , * fooBarObj },
1611
+ },
1612
+ {
1613
+ name : "NonRecursive on object key (prefix) returns object and no other objects with the same prefix" ,
1614
+ key : fooKey ,
1615
+ recursive : false ,
1616
+ expectedOut : []example.Pod {* fooObj },
1617
+ },
1618
+ {
1619
+ name : "Recursive on object key (prefix) doesn't return anything" ,
1620
+ key : fooKey ,
1621
+ recursive : true ,
1622
+ expectedOut : []example.Pod {},
1623
+ },
1624
+ {
1625
+ name : "NonRecursive on object key (no-prefix) return object" ,
1626
+ key : fooBarKey ,
1627
+ recursive : false ,
1628
+ expectedOut : []example.Pod {* fooBarObj },
1629
+ },
1630
+ {
1631
+ name : "Recursive on object key (no-prefix) doesn't return anything" ,
1632
+ key : fooBarKey ,
1633
+ recursive : true ,
1634
+ expectedOut : []example.Pod {},
1635
+ },
1636
+ }
1637
+
1638
+ for _ , tt := range tests {
1639
+ tt := tt
1640
+ t .Run (tt .name , func (t * testing.T ) {
1641
+ out := & example.PodList {}
1642
+ storageOpts := storage.ListOptions {
1643
+ Recursive : tt .recursive ,
1644
+ Predicate : storage .Everything ,
1645
+ }
1646
+ err := store .GetList (ctx , tt .key , storageOpts , out )
1647
+ if err != nil {
1648
+ t .Fatalf ("GetList failed: %v" , err )
1649
+ }
1650
+ expectNoDiff (t , "incorrect list pods" , tt .expectedOut , out .Items )
1651
+ })
1652
+ }
1653
+ }
1654
+
1576
1655
type CallsValidation func (t * testing.T , pageSize , estimatedProcessedObjects uint64 )
1577
1656
1578
1657
func RunTestListContinuation (ctx context.Context , t * testing.T , store storage.Interface , validation CallsValidation ) {
0 commit comments