InteroperabilityTestCase.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 13.0, iOS 16.0, watchOS 9.0, tvOS 16.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
  29. /// specification](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
  33. /// - client-compressed-unary
  34. /// - server-compressed-unary
  35. /// - client_compressed_streaming
  36. /// - server_compressed_streaming
  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. /// - cancel_after_begin
  44. /// - cancel_after_first_response
  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 {
  50. case emptyUnary = "empty_unary"
  51. case largeUnary = "large_unary"
  52. case clientStreaming = "client_streaming"
  53. case serverStreaming = "server_streaming"
  54. case pingPong = "ping_pong"
  55. case emptyStream = "empty_stream"
  56. case customMetadata = "custom_metadata"
  57. case statusCodeAndMessage = "status_code_and_message"
  58. case specialStatusMessage = "special_status_message"
  59. case unimplementedMethod = "unimplemented_method"
  60. case unimplementedService = "unimplemented_service"
  61. public var name: String {
  62. return self.rawValue
  63. }
  64. }
  65. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
  66. extension InteroperabilityTestCase {
  67. /// Return a new instance of the test case.
  68. public func makeTest() -> InteroperabilityTest {
  69. switch self {
  70. case .emptyUnary:
  71. return EmptyUnary()
  72. case .largeUnary:
  73. return LargeUnary()
  74. case .clientStreaming:
  75. return ClientStreaming()
  76. case .serverStreaming:
  77. return ServerStreaming()
  78. case .pingPong:
  79. return PingPong()
  80. case .emptyStream:
  81. return EmptyStream()
  82. case .customMetadata:
  83. return CustomMetadata()
  84. case .statusCodeAndMessage:
  85. return StatusCodeAndMessage()
  86. case .specialStatusMessage:
  87. return SpecialStatusMessage()
  88. case .unimplementedMethod:
  89. return UnimplementedMethod()
  90. case .unimplementedService:
  91. return UnimplementedService()
  92. }
  93. }
  94. }