/* * Copyright 2019, 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 import XCTest import NIO import NIOHTTP1 @testable import GRPC import EchoModel import EchoImplementation import Logging class HTTP1ToGRPCServerCodecTests: GRPCTestCase { var channel: EmbeddedChannel! override func setUp() { super.setUp() let handler = HTTP1ToGRPCServerCodec(encoding: .disabled, logger: self.logger) self.channel = EmbeddedChannel(handler: handler) } override func tearDown() { XCTAssertNoThrow(try self.channel.finish()) super.tearDown() } func makeRequestHead() -> HTTPRequestHead { return HTTPRequestHead( version: .init(major: 2, minor: 0), method: .POST, uri: "/echo.Echo/Get" ) } func testSingleMessageFromMultipleBodyParts() throws { XCTAssertNoThrow(try self.channel.writeInbound(HTTPServerRequestPart.head(self.makeRequestHead()))) let requestPart = try self.channel.readInbound(as: _RawGRPCServerRequestPart.self) switch requestPart { case .some(.head): () default: XCTFail("Unexpected request part: \(String(describing: requestPart))") } // Write a message across multiple buffers. let message = Echo_EchoRequest.with { $0.text = String(repeating: "x", count: 42) } let data = try message.serializedData() // Split the payload into two parts. let halfIndex = data.count / 2 let firstChunk = data[0..