From 22dee417f0f0b58a44e4bc9fc2c10f94c02795d7 Mon Sep 17 00:00:00 2001 From: Daniel Alm Date: Mon, 18 Jun 2018 16:31:11 +0200 Subject: [PATCH] Add a few more tests to ensure that trailing metadata is sent as expected. --- Tests/LinuxMain.swift | 1 + Tests/SwiftGRPCTests/MetadataTests.swift | 25 +++++++++++++++++++ .../SwiftGRPCTests/ServerThrowingTests.swift | 5 +++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Tests/SwiftGRPCTests/MetadataTests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 5b713f7f3..50cc6530f 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -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), diff --git a/Tests/SwiftGRPCTests/MetadataTests.swift b/Tests/SwiftGRPCTests/MetadataTests.swift new file mode 100644 index 000000000..b93c98224 --- /dev/null +++ b/Tests/SwiftGRPCTests/MetadataTests.swift @@ -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) + } +} diff --git a/Tests/SwiftGRPCTests/ServerThrowingTests.swift b/Tests/SwiftGRPCTests/ServerThrowingTests.swift index 17740222d..fa9456817 100644 --- a/Tests/SwiftGRPCTests/ServerThrowingTests.swift +++ b/Tests/SwiftGRPCTests/ServerThrowingTests.swift @@ -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? { @@ -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) } }