AnyServiceClientTests.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 EchoModel
  17. import Foundation
  18. import GRPC
  19. import XCTest
  20. class AnyServiceClientTests: EchoTestCaseBase {
  21. var anyServiceClient: GRPCAnyServiceClient {
  22. return GRPCAnyServiceClient(
  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. )
  33. XCTAssertEqual(try get.status.map { $0.code }.wait(), .ok)
  34. }
  35. func testClientStreaming() throws {
  36. let collect = self.anyServiceClient.makeClientStreamingCall(
  37. path: "/echo.Echo/Collect",
  38. requestType: Echo_EchoRequest.self,
  39. responseType: Echo_EchoResponse.self
  40. )
  41. collect.sendEnd(promise: nil)
  42. XCTAssertEqual(try collect.status.map { $0.code }.wait(), .ok)
  43. }
  44. func testServerStreaming() throws {
  45. let expand = self.anyServiceClient.makeServerStreamingCall(
  46. path: "/echo.Echo/Expand",
  47. request: Echo_EchoRequest.with { $0.text = "foo" },
  48. responseType: Echo_EchoResponse.self,
  49. handler: { _ in }
  50. )
  51. XCTAssertEqual(try expand.status.map { $0.code }.wait(), .ok)
  52. }
  53. func testBidirectionalStreaming() throws {
  54. let update = self.anyServiceClient.makeBidirectionalStreamingCall(
  55. path: "/echo.Echo/Update",
  56. requestType: Echo_EchoRequest.self,
  57. responseType: Echo_EchoResponse.self,
  58. handler: { _ in }
  59. )
  60. update.sendEnd(promise: nil)
  61. XCTAssertEqual(try update.status.map { $0.code }.wait(), .ok)
  62. }
  63. }