Skip to content

Commit 6765abb

Browse files
committed
Add pipeline operation tests
1 parent b7db7ab commit 6765abb

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Testing
18+
19+
@testable import GRPCCore
20+
21+
@Suite("ClientInterceptorPipelineOperation")
22+
struct ClientInterceptorPipelineOperationTests {
23+
@Suite("Applies to")
24+
struct AppliesToTests {
25+
@Test
26+
func all() async throws {
27+
let operation = ClientInterceptorPipelineOperation.apply(
28+
.requestCounter(.init()),
29+
to: .all
30+
)
31+
32+
#expect(operation.applies(to: MethodDescriptor(service: "foo", method: "bar")))
33+
#expect(operation.applies(to: MethodDescriptor(service: "foo", method: "baz")))
34+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "foo")))
35+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "baz")))
36+
}
37+
38+
@Test
39+
func serviceSpecific() async throws {
40+
let operation = ClientInterceptorPipelineOperation.apply(
41+
.requestCounter(.init()),
42+
to: .services(Set([ServiceDescriptor(package: "pkg", service: "foo")]))
43+
)
44+
45+
#expect(operation.applies(to: MethodDescriptor(service: "pkg.foo", method: "bar")))
46+
#expect(operation.applies(to: MethodDescriptor(service: "pkg.foo", method: "baz")))
47+
48+
#expect(!operation.applies(to: MethodDescriptor(service: "pkg.bar", method: "foo")))
49+
#expect(!operation.applies(to: MethodDescriptor(service: "pkg.bar", method: "baz")))
50+
}
51+
52+
@Test
53+
func methodSpecific() async throws {
54+
let operation = ClientInterceptorPipelineOperation.apply(
55+
.requestCounter(.init()),
56+
to: .methods(Set([MethodDescriptor(service: "bar", method: "foo")]))
57+
)
58+
59+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "foo")))
60+
61+
#expect(!operation.applies(to: MethodDescriptor(service: "foo", method: "bar")))
62+
#expect(!operation.applies(to: MethodDescriptor(service: "foo", method: "baz")))
63+
#expect(!operation.applies(to: MethodDescriptor(service: "bar", method: "baz")))
64+
}
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Testing
18+
19+
@testable import GRPCCore
20+
21+
@Suite("ServerInterceptorPipelineOperation")
22+
struct ServerInterceptorPipelineOperationTests {
23+
@Suite("Applies to")
24+
struct AppliesToTests {
25+
@Test
26+
func all() async throws {
27+
let operation = ServerInterceptorPipelineOperation.apply(
28+
.requestCounter(.init()),
29+
to: .all
30+
)
31+
32+
#expect(operation.applies(to: MethodDescriptor(service: "foo", method: "bar")))
33+
#expect(operation.applies(to: MethodDescriptor(service: "foo", method: "baz")))
34+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "foo")))
35+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "baz")))
36+
}
37+
38+
@Test
39+
func serviceSpecific() async throws {
40+
let operation = ServerInterceptorPipelineOperation.apply(
41+
.requestCounter(.init()),
42+
to: .services(Set([ServiceDescriptor(package: "pkg", service: "foo")]))
43+
)
44+
45+
#expect(operation.applies(to: MethodDescriptor(service: "pkg.foo", method: "bar")))
46+
#expect(operation.applies(to: MethodDescriptor(service: "pkg.foo", method: "baz")))
47+
48+
#expect(!operation.applies(to: MethodDescriptor(service: "pkg.bar", method: "foo")))
49+
#expect(!operation.applies(to: MethodDescriptor(service: "pkg.bar", method: "baz")))
50+
}
51+
52+
@Test
53+
func methodSpecific() async throws {
54+
let operation = ServerInterceptorPipelineOperation.apply(
55+
.requestCounter(.init()),
56+
to: .methods(Set([MethodDescriptor(service: "bar", method: "foo")]))
57+
)
58+
59+
#expect(operation.applies(to: MethodDescriptor(service: "bar", method: "foo")))
60+
61+
#expect(!operation.applies(to: MethodDescriptor(service: "foo", method: "bar")))
62+
#expect(!operation.applies(to: MethodDescriptor(service: "foo", method: "baz")))
63+
#expect(!operation.applies(to: MethodDescriptor(service: "bar", method: "baz")))
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)