@@ -20,7 +20,7 @@ import Testing
20
20
@Suite ( " ConditionalInterceptor " )
21
21
struct ConditionalInterceptorTests {
22
22
@Test (
23
- " Applies to " ,
23
+ " Applies to all, services and methods " ,
24
24
arguments: [
25
25
(
26
26
. all,
@@ -37,6 +37,26 @@ struct ConditionalInterceptorTests {
37
37
[ . barFoo] ,
38
38
[ . fooBar, . fooBaz, . barBaz]
39
39
) ,
40
+ ] as [ ( ConditionalInterceptor < any Sendable > . Subject , [ MethodDescriptor ] , [ MethodDescriptor ] ) ]
41
+ )
42
+ @available ( gRPCSwift 2 . 0 , * )
43
+ func appliesTo(
44
+ target: ConditionalInterceptor < any Sendable > . Subject ,
45
+ applicableMethods: [ MethodDescriptor ] ,
46
+ notApplicableMethods: [ MethodDescriptor ]
47
+ ) {
48
+ for applicableMethod in applicableMethods {
49
+ #expect( target. applies ( to: applicableMethod) )
50
+ }
51
+
52
+ for notApplicableMethod in notApplicableMethods {
53
+ #expect( !target. applies ( to: notApplicableMethod) )
54
+ }
55
+ }
56
+
57
+ @Test (
58
+ " Applies to only and allExcluding " ,
59
+ arguments: [
40
60
(
41
61
. only( services: [ . foo] , methods: [ . barFoo] ) ,
42
62
[ . fooBar, . fooBaz, . barFoo] ,
@@ -47,17 +67,10 @@ struct ConditionalInterceptorTests {
47
67
[ . barBaz] ,
48
68
[ . fooBar, . fooBaz, . barFoo]
49
69
) ,
50
- (
51
- . allMatching { ( _ descriptor: MethodDescriptor ) -> Bool in
52
- descriptor. method == " baz "
53
- } ,
54
- [ . fooBaz, . barBaz] ,
55
- [ . fooBar, . barFoo]
56
- ) ,
57
70
] as [ ( ConditionalInterceptor < any Sendable > . Subject , [ MethodDescriptor ] , [ MethodDescriptor ] ) ]
58
71
)
59
- @available ( gRPCSwift 2 . 0 , * )
60
- func appliesTo (
72
+ @available ( gRPCSwift 2 . 2 , * )
73
+ func appliesToOnlyAndAllExcluding (
61
74
target: ConditionalInterceptor < any Sendable > . Subject ,
62
75
applicableMethods: [ MethodDescriptor ] ,
63
76
notApplicableMethods: [ MethodDescriptor ]
@@ -70,6 +83,24 @@ struct ConditionalInterceptorTests {
70
83
#expect( !target. applies ( to: notApplicableMethod) )
71
84
}
72
85
}
86
+
87
+ @Test ( " Applies to all matching " )
88
+ @available ( gRPCSwift 2 . 2 , * )
89
+ func appliesToAllMatching( ) {
90
+ let target = ConditionalInterceptor < any Sendable > . Subject. allMatching { descriptor in
91
+ descriptor. method == " baz "
92
+ }
93
+ let applicableMethods : [ MethodDescriptor ] = [ . fooBaz, . barBaz]
94
+ let notApplicableMethods : [ MethodDescriptor ] = [ . fooBar, . barFoo]
95
+
96
+ for applicableMethod in applicableMethods {
97
+ #expect( target. applies ( to: applicableMethod) )
98
+ }
99
+
100
+ for notApplicableMethod in notApplicableMethods {
101
+ #expect( !target. applies ( to: notApplicableMethod) )
102
+ }
103
+ }
73
104
}
74
105
75
106
@available ( gRPCSwift 2 . 2 , * )
0 commit comments