ChannelArgumentTests.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2018, 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. #if SWIFT_PACKAGE
  17. import CgRPC
  18. #endif
  19. import Foundation
  20. @testable import SwiftGRPC
  21. import XCTest
  22. class ChannelArgumentTests: XCTestCase {
  23. func testArgumentKey() {
  24. let argument: Channel.Argument = .defaultAuthority("default")
  25. XCTAssertEqual(String(cString: argument.toCArg().key), "grpc.default_authority")
  26. }
  27. func testStringArgument() {
  28. let argument: Channel.Argument = .primaryUserAgent("Primary/0.1")
  29. XCTAssertEqual(String(cString: argument.toCArg().value.string), "Primary/0.1")
  30. }
  31. func testIntegerArgument() {
  32. let argument: Channel.Argument = .http2MaxPingsWithoutData(5)
  33. XCTAssertEqual(argument.toCArg().value.integer, 5)
  34. }
  35. func testBoolArgument() {
  36. let argument: Channel.Argument = .keepAlivePermitWithoutCalls(true)
  37. XCTAssertEqual(argument.toCArg().value.integer, 1)
  38. }
  39. func testTimeIntervalArgument() {
  40. let argument: Channel.Argument = .keepAliveTime(2.5)
  41. XCTAssertEqual(argument.toCArg().value.integer, 2500) // in ms
  42. }
  43. }