2
0

InteroperabilityTestCase.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2024, 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 GRPCCore
  17. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  18. public protocol InteroperabilityTest {
  19. /// Run a test case using the given connection.
  20. ///
  21. /// The test case is considered unsuccessful if any exception is thrown, conversely if no
  22. /// exceptions are thrown it is successful.
  23. ///
  24. /// - Parameter client: The client to use for the test.
  25. /// - Throws: Any exception may be thrown to indicate an unsuccessful test.
  26. func run(client: GRPCClient) async throws
  27. }
  28. /// Test cases as listed by the [gRPC interoperability test description specification]
  29. /// (https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md).
  30. ///
  31. /// This is not a complete list, the following tests have not been implemented:
  32. /// - cacheable_unary (caching not supported)
  33. /// - cancel_after_begin (if the client cancels the task running the request, there's no response to be
  34. /// received, so we can't check we got back a Cancelled status code)
  35. /// - cancel_after_first_response (same reason as above)
  36. /// - client_compressed_streaming (we don't support per-message compression, so we can't implement this)
  37. /// - compute_engine_creds
  38. /// - jwt_token_creds
  39. /// - oauth2_auth_token
  40. /// - per_rpc_creds
  41. /// - google_default_credentials
  42. /// - compute_engine_channel_credentials
  43. /// - timeout_on_sleeping_server (timeouts end up being surfaced as `CancellationError`s, so we
  44. /// can't really implement this test)
  45. ///
  46. /// Note: Tests for compression have not been implemented yet as compression is
  47. /// not supported. Once the API which allows for compression will be implemented
  48. /// these tests should be added.
  49. public enum InteroperabilityTestCase: String, CaseIterable, Sendable {
  50. case emptyUnary = "empty_unary"
  51. case largeUnary = "large_unary"
  52. case clientCompressedUnary = "client_compressed_unary"
  53. case serverCompressedUnary = "server_compressed_unary"
  54. case clientStreaming = "client_streaming"
  55. case serverStreaming = "server_streaming"
  56. case serverCompressedStreaming = "server_compressed_streaming"
  57. case pingPong = "ping_pong"
  58. case emptyStream = "empty_stream"
  59. case customMetadata = "custom_metadata"
  60. case statusCodeAndMessage = "status_code_and_message"
  61. case specialStatusMessage = "special_status_message"
  62. case unimplementedMethod = "unimplemented_method"
  63. case unimplementedService = "unimplemented_service"
  64. public var name: String {
  65. return self.rawValue
  66. }
  67. }
  68. @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
  69. extension InteroperabilityTestCase {
  70. /// Return a new instance of the test case.
  71. public func makeTest() -> any InteroperabilityTest {
  72. switch self {
  73. case .emptyUnary:
  74. return EmptyUnary()
  75. case .largeUnary:
  76. return LargeUnary()
  77. case .clientCompressedUnary:
  78. return ClientCompressedUnary()
  79. case .serverCompressedUnary:
  80. return ServerCompressedUnary()
  81. case .clientStreaming:
  82. return ClientStreaming()
  83. case .serverStreaming:
  84. return ServerStreaming()
  85. case .serverCompressedStreaming:
  86. return ServerCompressedStreaming()
  87. case .pingPong:
  88. return PingPong()
  89. case .emptyStream:
  90. return EmptyStream()
  91. case .customMetadata:
  92. return CustomMetadata()
  93. case .statusCodeAndMessage:
  94. return StatusCodeAndMessage()
  95. case .specialStatusMessage:
  96. return SpecialStatusMessage()
  97. case .unimplementedMethod:
  98. return UnimplementedMethod()
  99. case .unimplementedService:
  100. return UnimplementedService()
  101. }
  102. }
  103. }