Skip to content

Commit

Permalink
Add a few more tests to ensure that trailing metadata is sent as expe…
Browse files Browse the repository at this point in the history
…cted.
  • Loading branch information
MrMage committed Jun 18, 2018
1 parent 0d511b3 commit 22dee41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ XCTMain([
testCase(CompletionQueueTests.allTests),
testCase(ConnectionFailureTests.allTests),
testCase(EchoTests.allTests),
testCase(MetadataTests.allTests),
testCase(ServerCancellingTests.allTests),
testCase(ServerTestExample.allTests),
testCase(ServerThrowingTests.allTests),
Expand Down
25 changes: 25 additions & 0 deletions Tests/SwiftGRPCTests/MetadataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2018, gRPC Authors All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
@testable import SwiftGRPC
import XCTest

class MetadataTests: XCTestCase {
func testMetadata() {
let metadata = try! Metadata(["foo": "bar"])
XCTAssertEqual(["foo": "bar"], metadata.copy().dictionaryRepresentation)
}
}
5 changes: 4 additions & 1 deletion Tests/SwiftGRPCTests/ServerThrowingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import Foundation
import XCTest

fileprivate let testStatus = ServerStatus(code: .permissionDenied, message: "custom status message")
fileprivate let testStatusWithTrailingMetadata = ServerStatus(code: .permissionDenied, message: "custom status message",
trailingMetadata: try! Metadata(["foo": "bar"]))

fileprivate class StatusThrowingProvider: Echo_EchoProvider {
func get(request: Echo_EchoRequest, session _: Echo_EchoGetSession) throws -> Echo_EchoResponse {
throw testStatus
throw testStatusWithTrailingMetadata
}

func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws -> ServerStatus? {
Expand Down Expand Up @@ -61,6 +63,7 @@ extension ServerThrowingTests {
else { XCTFail("unexpected error \(error)"); return }
XCTAssertEqual(.permissionDenied, callResult.statusCode)
XCTAssertEqual("custom status message", callResult.statusMessage)
XCTAssertEqual(["foo": "bar"], callResult.trailingMetadata?.dictionaryRepresentation)
}
}

Expand Down

0 comments on commit 22dee41

Please sign in to comment.