@@ -6657,3 +6657,86 @@ func TestMigrateStatus(t *testing.T) {
6657
6657
})
6658
6658
}
6659
6659
}
6660
+
6661
+ func TestIgnoreNotAllowedNamespaces (t * testing.T ) {
6662
+ tests := []struct {
6663
+ name string
6664
+ namespaces []string
6665
+ objectNS string
6666
+ expected bool
6667
+ }{
6668
+ {
6669
+ name : "Namespace allowed" ,
6670
+ namespaces : []string {"allowed-namespace" },
6671
+ objectNS : "allowed-namespace" ,
6672
+ expected : true ,
6673
+ },
6674
+ {
6675
+ name : "Namespace not allowed" ,
6676
+ namespaces : []string {"allowed-namespace" },
6677
+ objectNS : "not-allowed-namespace" ,
6678
+ expected : false ,
6679
+ },
6680
+ {
6681
+ name : "Empty allowed namespaces" ,
6682
+ namespaces : []string {},
6683
+ objectNS : "any-namespace" ,
6684
+ expected : false ,
6685
+ },
6686
+ {
6687
+ name : "Multiple allowed namespaces" ,
6688
+ namespaces : []string {"allowed-namespace-1" , "allowed-namespace-2" },
6689
+ objectNS : "allowed-namespace-2" ,
6690
+ expected : true ,
6691
+ },
6692
+ {
6693
+ name : "Namespace not in multiple allowed namespaces" ,
6694
+ namespaces : []string {"allowed-namespace-1" , "allowed-namespace-2" },
6695
+ objectNS : "not-allowed-namespace" ,
6696
+ expected : false ,
6697
+ },
6698
+ {
6699
+ name : "Namespace matched by glob pattern" ,
6700
+ namespaces : []string {"allowed-namespace-*" },
6701
+ objectNS : "allowed-namespace-1" ,
6702
+ expected : true ,
6703
+ },
6704
+ {
6705
+ name : "Namespace matched by regex pattern" ,
6706
+ namespaces : []string {"/^allowed-namespace-[^-]+$/" },
6707
+ objectNS : "allowed-namespace-1" ,
6708
+ expected : true ,
6709
+ },
6710
+ }
6711
+
6712
+ for _ , tt := range tests {
6713
+ t .Run (tt .name , func (t * testing.T ) {
6714
+ predicate := ignoreNotAllowedNamespaces (tt .namespaces )
6715
+ object := & v1alpha1.ApplicationSet {
6716
+ ObjectMeta : metav1.ObjectMeta {
6717
+ Namespace : tt .objectNS ,
6718
+ },
6719
+ }
6720
+
6721
+ t .Run (tt .name + ":Create" , func (t * testing.T ) {
6722
+ result := predicate .Create (event.CreateEvent {Object : object })
6723
+ assert .Equal (t , tt .expected , result )
6724
+ })
6725
+
6726
+ t .Run (tt .name + ":Update" , func (t * testing.T ) {
6727
+ result := predicate .Update (event.UpdateEvent {ObjectNew : object })
6728
+ assert .Equal (t , tt .expected , result )
6729
+ })
6730
+
6731
+ t .Run (tt .name + ":Delete" , func (t * testing.T ) {
6732
+ result := predicate .Delete (event.DeleteEvent {Object : object })
6733
+ assert .Equal (t , tt .expected , result )
6734
+ })
6735
+
6736
+ t .Run (tt .name + ":Generic" , func (t * testing.T ) {
6737
+ result := predicate .Generic (event.GenericEvent {Object : object })
6738
+ assert .Equal (t , tt .expected , result )
6739
+ })
6740
+ })
6741
+ }
6742
+ }
0 commit comments