From 140d34a0551ddd17de643462d7a5111be9d5d803 Mon Sep 17 00:00:00 2001 From: Martin Petrov <357181+mpetrov@users.noreply.github.com> Date: Wed, 6 Mar 2019 11:15:08 -0500 Subject: [PATCH] Add public factory methods for CallResult. (#394) * Add public factory methods for CallResult. This enables instantiating CallResult structs for test stubs. * Also set metadata. --- Sources/SwiftGRPC/Core/CallResult.swift | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sources/SwiftGRPC/Core/CallResult.swift b/Sources/SwiftGRPC/Core/CallResult.swift index 3972acd10..697b17e6d 100644 --- a/Sources/SwiftGRPC/Core/CallResult.swift +++ b/Sources/SwiftGRPC/Core/CallResult.swift @@ -26,6 +26,35 @@ public struct CallResult: CustomStringConvertible { public let resultData: Data? public let initialMetadata: Metadata? public let trailingMetadata: Metadata? + + public static func error( + statusCode: StatusCode = .unknown, + statusMessage: String? = nil, + initialMetadata: Metadata? = nil, + trailingMetadata: Metadata? = nil + ) -> CallResult { + return CallResult( + success: false, + statusCode: statusCode, + statusMessage: statusMessage, + resultData: nil, + initialMetadata: initialMetadata, + trailingMetadata: trailingMetadata) + } + + public static func success( + resultData: Data, + initialMetadata: Metadata? = nil, + trailingMetadata: Metadata? = nil + ) -> CallResult { + return CallResult( + success: true, + statusCode: .ok, + statusMessage: "OK", + resultData: resultData, + initialMetadata: initialMetadata, + trailingMetadata: trailingMetadata) + } init(_ op: OperationGroup) { success = op.success