Skip to content

Commit

Permalink
Add public factory methods for CallResult. (#394)
Browse files Browse the repository at this point in the history
* Add public factory methods for CallResult.

This enables instantiating CallResult structs for test stubs.

* Also set metadata.
  • Loading branch information
mpetrov authored and MrMage committed Mar 6, 2019
1 parent 30a7fbc commit 140d34a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Sources/SwiftGRPC/Core/CallResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 140d34a

Please sign in to comment.