Skip to content

Commit 6743dce

Browse files
split conditional interceptor tests
1 parent 178884f commit 6743dce

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

Tests/GRPCCoreTests/Call/ConditionalInterceptorTests.swift

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Testing
2020
@Suite("ConditionalInterceptor")
2121
struct ConditionalInterceptorTests {
2222
@Test(
23-
"Applies to",
23+
"Applies to all, services and methods",
2424
arguments: [
2525
(
2626
.all,
@@ -37,6 +37,26 @@ struct ConditionalInterceptorTests {
3737
[.barFoo],
3838
[.fooBar, .fooBaz, .barBaz]
3939
),
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: [
4060
(
4161
.only(services: [.foo], methods: [.barFoo]),
4262
[.fooBar, .fooBaz, .barFoo],
@@ -47,17 +67,10 @@ struct ConditionalInterceptorTests {
4767
[.barBaz],
4868
[.fooBar, .fooBaz, .barFoo]
4969
),
50-
(
51-
.allMatching { (_ descriptor: MethodDescriptor) -> Bool in
52-
descriptor.method == "baz"
53-
},
54-
[.fooBaz, .barBaz],
55-
[.fooBar, .barFoo]
56-
),
5770
] as [(ConditionalInterceptor<any Sendable>.Subject, [MethodDescriptor], [MethodDescriptor])]
5871
)
59-
@available(gRPCSwift 2.0, *)
60-
func appliesTo(
72+
@available(gRPCSwift 2.2, *)
73+
func appliesToOnlyAndAllExcluding(
6174
target: ConditionalInterceptor<any Sendable>.Subject,
6275
applicableMethods: [MethodDescriptor],
6376
notApplicableMethods: [MethodDescriptor]
@@ -70,6 +83,24 @@ struct ConditionalInterceptorTests {
7083
#expect(!target.applies(to: notApplicableMethod))
7184
}
7285
}
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+
}
73104
}
74105

75106
@available(gRPCSwift 2.2, *)

0 commit comments

Comments
 (0)