Browse Source

Add a few more tests to ensure that trailing metadata is sent as expected.

Daniel Alm 7 years ago
parent
commit
22dee417f0

+ 1 - 0
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),

+ 25 - 0
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)
+  }
+}

+ 4 - 1
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)
     }
   }