AnyServiceClientTests.swift 2.1 KB

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