AnyServiceClientTests.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2019, 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. import Foundation
  17. import GRPC
  18. import EchoModel
  19. import XCTest
  20. class AnyServiceClientTests: EchoTestCaseBase {
  21. var anyServiceClient: AnyServiceClient {
  22. return AnyServiceClient(
  23. channel: self.client.channel,
  24. defaultCallOptions: self.callOptionsWithLogger
  25. )
  26. }
  27. func testUnary() throws {
  28. let get = self.anyServiceClient.makeUnaryCall(
  29. path: "/echo.Echo/Get",
  30. request: Echo_EchoRequest.with { $0.text = "foo" },
  31. responseType: Echo_EchoResponse.self)
  32. XCTAssertEqual(try get.status.map { $0.code }.wait(), .ok)
  33. }
  34. func testClientStreaming() throws {
  35. let collect = self.anyServiceClient.makeClientStreamingCall(
  36. path: "/echo.Echo/Collect",
  37. requestType: Echo_EchoRequest.self,
  38. responseType: Echo_EchoResponse.self)
  39. collect.sendEnd(promise: nil)
  40. XCTAssertEqual(try collect.status.map { $0.code }.wait(), .ok)
  41. }
  42. func testServerStreaming() throws {
  43. let expand = self.anyServiceClient.makeServerStreamingCall(
  44. path: "/echo.Echo/Expand",
  45. request: Echo_EchoRequest.with { $0.text = "foo" },
  46. responseType: Echo_EchoResponse.self,
  47. handler: { _ in })
  48. XCTAssertEqual(try expand.status.map { $0.code }.wait(), .ok)
  49. }
  50. func testBidirectionalStreaming() throws {
  51. let update = self.anyServiceClient.makeBidirectionalStreamingCall(
  52. path: "/echo.Echo/Update",
  53. requestType: Echo_EchoRequest.self,
  54. responseType: Echo_EchoResponse.self,
  55. handler: { _ in })
  56. update.sendEnd(promise: nil)
  57. XCTAssertEqual(try update.status.map { $0.code }.wait(), .ok)
  58. }
  59. }