AnyServiceClientTests.swift 2.1 KB

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