InteroperabilityTestsExecutable.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ArgumentParser
  17. import GRPCCore
  18. import GRPCHTTP2Core
  19. import GRPCHTTP2TransportNIOPosix
  20. import InteroperabilityTests
  21. import NIOPosix
  22. @main
  23. @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
  24. struct InteroperabilityTestsExecutable: AsyncParsableCommand {
  25. static var configuration = CommandConfiguration(
  26. abstract: "gRPC Swift Interoperability Runner",
  27. subcommands: [StartServer.self, ListTests.self]
  28. )
  29. struct StartServer: AsyncParsableCommand {
  30. static var configuration = CommandConfiguration(
  31. abstract: "Start the gRPC Swift interoperability test server."
  32. )
  33. @Option(help: "The port to listen on for new connections")
  34. var port: Int
  35. func run() async throws {
  36. var transportConfig = HTTP2ServerTransport.Posix.Config.defaults
  37. transportConfig.compression.enabledAlgorithms = .all
  38. let transport = HTTP2ServerTransport.Posix(
  39. address: .ipv4(host: "0.0.0.0", port: self.port),
  40. config: transportConfig
  41. )
  42. let server = GRPCServer(transport: transport, services: [TestService()])
  43. try await server.run()
  44. }
  45. }
  46. struct ListTests: ParsableCommand {
  47. static var configuration = CommandConfiguration(
  48. abstract: "List all interoperability test names."
  49. )
  50. func run() throws {
  51. for testCase in InteroperabilityTestCase.allCases {
  52. print(testCase.name)
  53. }
  54. }
  55. }
  56. }