Connection+Equatable.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. @testable import GRPCHTTP2Core
  18. @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
  19. extension Connection.Event: Equatable {
  20. public static func == (lhs: Connection.Event, rhs: Connection.Event) -> Bool {
  21. switch (lhs, rhs) {
  22. case (.connectSucceeded, .connectSucceeded),
  23. (.connectFailed, .connectFailed):
  24. return true
  25. case (.goingAway(let lhsCode, let lhsReason), .goingAway(let rhsCode, let rhsReason)):
  26. return lhsCode == rhsCode && lhsReason == rhsReason
  27. case (.closed(let lhsReason), .closed(let rhsReason)):
  28. return lhsReason == rhsReason
  29. default:
  30. return false
  31. }
  32. }
  33. }
  34. @available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)
  35. extension Connection.CloseReason: Equatable {
  36. public static func == (lhs: Connection.CloseReason, rhs: Connection.CloseReason) -> Bool {
  37. switch (lhs, rhs) {
  38. case (.idleTimeout, .idleTimeout),
  39. (.keepaliveTimeout, .keepaliveTimeout),
  40. (.initiatedLocally, .initiatedLocally),
  41. (.remote, .remote):
  42. return true
  43. case (.error(let lhsError), .error(let rhsError)):
  44. if let lhs = lhsError as? RPCError, let rhs = rhsError as? RPCError {
  45. return lhs == rhs
  46. } else {
  47. return true
  48. }
  49. default:
  50. return false
  51. }
  52. }
  53. }