forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose public creation methods for
GRPCAsyncRequestStream
and `GRPC…
…AsyncResponseStreamWriter` (grpc#1485) Motivation: It is highly desirable to be able to write tests against the generated method of a service. Currently, this is close to impossible since both the `GRPCAsyncRequestStream` and the `GRPCAsyncResponseStreamWriter` don't expose a public init so users cannot drive and observe the functions. Modification: Adds new public methods to drive and observe the request stream and the response writer. Result We can now test functions which use the request stream and response stream writer.
- Loading branch information
1 parent
fb0a898
commit 6ad7c0b
Showing
5 changed files
with
288 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Tests/GRPCTests/AsyncAwaitSupport/GRPCAsyncRequestStreamTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#if compiler(>=5.6) | ||
|
||
import GRPC | ||
import XCTest | ||
|
||
@available(macOS 12, iOS 13, tvOS 13, watchOS 6, *) | ||
final class GRPCAsyncRequestStreamTests: XCTestCase { | ||
func testRecorder() async throws { | ||
let testingStream = GRPCAsyncRequestStream<Int>.makeTestingRequestStream() | ||
|
||
testingStream.source.yield(1) | ||
testingStream.source.finish(throwing: nil) | ||
|
||
let results = try await testingStream.stream.collect() | ||
|
||
XCTAssertEqual(results, [1]) | ||
} | ||
} | ||
#endif |
34 changes: 34 additions & 0 deletions
34
Tests/GRPCTests/AsyncAwaitSupport/GRPCAsyncResponseStreamWriterTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2022, gRPC Authors All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#if compiler(>=5.6) | ||
|
||
import GRPC | ||
import XCTest | ||
|
||
@available(macOS 12, iOS 13, tvOS 13, watchOS 6, *) | ||
final class GRPCAsyncResponseStreamWriterTests: XCTestCase { | ||
func testRecorder() async throws { | ||
let responseStreamWriter = GRPCAsyncResponseStreamWriter<Int>.makeTestingResponseStreamWriter() | ||
|
||
try await responseStreamWriter.writer.send(1, compression: .disabled) | ||
responseStreamWriter.stream.finish() | ||
|
||
let results = try await responseStreamWriter.stream.collect() | ||
XCTAssertEqual(results[0].0, 1) | ||
XCTAssertEqual(results[0].1, .disabled) | ||
} | ||
} | ||
#endif |