diff --git a/Sources/SwiftGRPC/Core/Call.swift b/Sources/SwiftGRPC/Core/Call.swift index 60694b1ee..05ae3ec87 100644 --- a/Sources/SwiftGRPC/Core/Call.swift +++ b/Sources/SwiftGRPC/Core/Call.swift @@ -108,7 +108,7 @@ public struct CallResult: CustomStringConvertible { initialMetadata = op.receivedInitialMetadata() trailingMetadata = op.receivedTrailingMetadata() } else { - statusCode = .ok + statusCode = .unknown statusMessage = nil resultData = nil initialMetadata = nil diff --git a/Sources/protoc-gen-swiftgrpc/options.swift b/Sources/protoc-gen-swiftgrpc/options.swift index e515f1a21..c4ccc0792 100644 --- a/Sources/protoc-gen-swiftgrpc/options.swift +++ b/Sources/protoc-gen-swiftgrpc/options.swift @@ -85,7 +85,7 @@ class GeneratorOptions { } static func parseParameter(string: String?) -> [(key: String, value: String)] { - guard let string = string, string.characters.count > 0 else { + guard let string = string, !string.isEmpty else { return [] } let parts = string.components(separatedBy: ",") diff --git a/Tests/SwiftGRPCTests/GRPCTests.swift b/Tests/SwiftGRPCTests/GRPCTests.swift index 835ad06d6..d46554f30 100644 --- a/Tests/SwiftGRPCTests/GRPCTests.swift +++ b/Tests/SwiftGRPCTests/GRPCTests.swift @@ -44,13 +44,13 @@ let initialClientMetadata = "x": "xylophone", "y": "yu", "z": "zither" - ] +] let initialServerMetadata = [ "a": "Apple", "b": "Banana", "c": "Cherry" - ] +] let trailingServerMetadata = [ // We have more than ten entries here to ensure that even large metadata entries work @@ -68,11 +68,18 @@ let trailingServerMetadata = "10": "ten", "11": "eleven", "12": "twelve" - ] +] let steps = 10 -let hello = "/hello" -let statusCode = StatusCode.ok -let statusMessage = "OK" +let hello = "/hello.unary" +let helloServerStream = "/hello.server-stream" +let helloBiDiStream = "/hello.bidi-stream" + +// Return code/message for unary test +let oddStatusCode = StatusCode.ok +let oddStatusMessage = "OK" + +let evenStatusCode = StatusCode.notFound +let eventStatusMessage = "Not Found" func runTest(useSSL: Bool) { gRPC.initialize() @@ -87,9 +94,9 @@ func runTest(useSSL: Bool) { guard let certificate = try? String(contentsOf: certificateURL, encoding: .utf8), let key = try? String(contentsOf: keyURL, encoding: .utf8) - else { - // FIXME: We don't want tests to silently pass just because the certificates can't be loaded. - return + else { + // FIXME: We don't want tests to silently pass just because the certificates can't be loaded. + return } server = Server(address: address, key: key, @@ -135,15 +142,14 @@ func verify_metadata(_ metadata: Metadata, expected: [String: String], file: Sta } func runClient(useSSL: Bool) throws { - let message = clientText.data(using: .utf8) let channel: Channel if useSSL { let certificateURL = URL(fileURLWithPath: "Tests/ssl.crt") guard let certificates = try? String(contentsOf: certificateURL, encoding: .utf8) - else { - return + else { + return } let host = "example.com" channel = Channel(address: address, certificates: certificates, host: host) @@ -152,7 +158,15 @@ func runClient(useSSL: Bool) throws { } channel.host = host - for _ in 0..