EchoMetadataTests.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2021, 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 GRPC
  18. import XCTest
  19. internal final class EchoMetadataTests: GRPCTestCase {
  20. private func testServiceDescriptor(_ description: GRPCServiceDescriptor) {
  21. XCTAssertEqual(description.name, "Echo")
  22. XCTAssertEqual(description.fullName, "echo.Echo")
  23. XCTAssertEqual(description.methods.count, 4)
  24. if let get = description.methods.first(where: { $0.name == "Get" }) {
  25. self._testGet(get)
  26. } else {
  27. XCTFail("No 'Get' method found")
  28. }
  29. if let collect = description.methods.first(where: { $0.name == "Collect" }) {
  30. self._testCollect(collect)
  31. } else {
  32. XCTFail("No 'Collect' method found")
  33. }
  34. if let expand = description.methods.first(where: { $0.name == "Expand" }) {
  35. self._testExpand(expand)
  36. } else {
  37. XCTFail("No 'Expand' method found")
  38. }
  39. if let update = description.methods.first(where: { $0.name == "Update" }) {
  40. self._testUpdate(update)
  41. } else {
  42. XCTFail("No 'Update' method found")
  43. }
  44. }
  45. private func _testGet(_ description: GRPCMethodDescriptor) {
  46. XCTAssertEqual(description.name, "Get")
  47. XCTAssertEqual(description.fullName, "echo.Echo/Get")
  48. XCTAssertEqual(description.path, "/echo.Echo/Get")
  49. XCTAssertEqual(description.type, .unary)
  50. }
  51. private func _testCollect(_ description: GRPCMethodDescriptor) {
  52. XCTAssertEqual(description.name, "Collect")
  53. XCTAssertEqual(description.fullName, "echo.Echo/Collect")
  54. XCTAssertEqual(description.path, "/echo.Echo/Collect")
  55. XCTAssertEqual(description.type, .clientStreaming)
  56. }
  57. private func _testExpand(_ description: GRPCMethodDescriptor) {
  58. XCTAssertEqual(description.name, "Expand")
  59. XCTAssertEqual(description.fullName, "echo.Echo/Expand")
  60. XCTAssertEqual(description.path, "/echo.Echo/Expand")
  61. XCTAssertEqual(description.type, .serverStreaming)
  62. }
  63. private func _testUpdate(_ description: GRPCMethodDescriptor) {
  64. XCTAssertEqual(description.name, "Update")
  65. XCTAssertEqual(description.fullName, "echo.Echo/Update")
  66. XCTAssertEqual(description.path, "/echo.Echo/Update")
  67. XCTAssertEqual(description.type, .bidirectionalStreaming)
  68. }
  69. func testServiceDescriptor() {
  70. self.testServiceDescriptor(Echo_EchoClientMetadata.serviceDescriptor)
  71. self.testServiceDescriptor(Echo_EchoServerMetadata.serviceDescriptor)
  72. if #available(macOS 12, *) {
  73. self.testServiceDescriptor(Echo_EchoAsyncClient.serviceDescriptor)
  74. }
  75. }
  76. func testGet() {
  77. self._testGet(Echo_EchoClientMetadata.Methods.get)
  78. self._testGet(Echo_EchoServerMetadata.Methods.get)
  79. }
  80. func testCollect() {
  81. self._testCollect(Echo_EchoClientMetadata.Methods.collect)
  82. self._testCollect(Echo_EchoServerMetadata.Methods.collect)
  83. }
  84. func testExpand() {
  85. self._testExpand(Echo_EchoClientMetadata.Methods.expand)
  86. self._testExpand(Echo_EchoServerMetadata.Methods.expand)
  87. }
  88. func testUpdate() {
  89. self._testUpdate(Echo_EchoClientMetadata.Methods.update)
  90. self._testUpdate(Echo_EchoServerMetadata.Methods.update)
  91. }
  92. }