From e93c0585fd933a634b039ad9d6d7860cfe6aa6d9 Mon Sep 17 00:00:00 2001 From: Ondrej Rafaj Date: Fri, 18 Dec 2020 17:57:49 +0000 Subject: [PATCH] removing @testable --- .gitignore | 1 + .../Requests/HTTPRequest+Response.swift | 2 +- .../Response tools/Response+Checks.swift | 4 ++-- .../Response tools/Response+Getters.swift | 16 +++++++--------- Tests/VaporTestToolsTests/AppTests.swift | 6 +++--- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index e162157..fc7b81c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ DerivedData/ # End of https://www.gitignore.io/api/vapor /Package.resolved +/.swiftpm diff --git a/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Response.swift b/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Response.swift index 022b609..a039ba5 100644 --- a/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Response.swift +++ b/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Response.swift @@ -7,7 +7,7 @@ @_exported import Foundation @_exported import Vapor -@_exported @testable import NIO +@_exported import NIO extension TestableProperty where TestableType == HTTPRequest { diff --git a/Sources/VaporTestTools/Extensions/Response tools/Response+Checks.swift b/Sources/VaporTestTools/Extensions/Response tools/Response+Checks.swift index b9e3abe..6db2b14 100644 --- a/Sources/VaporTestTools/Extensions/Response tools/Response+Checks.swift +++ b/Sources/VaporTestTools/Extensions/Response tools/Response+Checks.swift @@ -6,8 +6,8 @@ // import Foundation -@testable import Vapor -@testable import NIO +import Vapor +import NIO extension TestableProperty where TestableType: Response { diff --git a/Sources/VaporTestTools/Extensions/Response tools/Response+Getters.swift b/Sources/VaporTestTools/Extensions/Response tools/Response+Getters.swift index 6cf16d0..5d790bc 100644 --- a/Sources/VaporTestTools/Extensions/Response tools/Response+Getters.swift +++ b/Sources/VaporTestTools/Extensions/Response tools/Response+Getters.swift @@ -6,8 +6,8 @@ // import Foundation -@testable import Vapor -@testable import NIO +import Vapor +import NIO extension TestableProperty where TestableType: Response { @@ -32,23 +32,21 @@ extension TestableProperty where TestableType: Response { /// Size of the content public var contentSize: Int? { - return element.content.container.http.body.data?.count + return contentString?.count } /// Get content string. Maximum of 0.5Mb of text will be returned public var contentString: String? { - guard let data = try? element.content.container.http.body.consumeData(max: 500000, on: fakeRequest()).wait() else { - return nil - } - return String(data: data, encoding: .utf8) + return contentString(encoding: .utf8) } /// Get content string with encoding. Maximum of 0.5Mb of text will be returned public func contentString(encoding: String.Encoding) -> String? { - guard let data = try? element.content.container.http.body.consumeData(max: 500000, on: fakeRequest()).wait() else { + guard let data = try? element.http.body.consumeData(on: element).wait() else { return nil } - return String(data: data, encoding: encoding) + let string = String(data: data, encoding: encoding) + return string } } diff --git a/Tests/VaporTestToolsTests/AppTests.swift b/Tests/VaporTestToolsTests/AppTests.swift index 563d43a..bc2a360 100644 --- a/Tests/VaporTestToolsTests/AppTests.swift +++ b/Tests/VaporTestToolsTests/AppTests.swift @@ -53,9 +53,9 @@ class GenericControllerTests: XCTestCase { res.testable.debug() XCTAssertTrue(res.testable.has(statusCode: .notFound), "Wrong status code") - XCTAssertFalse(res.testable.has(header: "Content-Type"), "Should not content type") - XCTAssertTrue(res.testable.has(contentLength: 9), "Wrong content length") - XCTAssertTrue(res.testable.has(content: "Not found"), "Incorrect content") + XCTAssertTrue(res.testable.has(header: "Content-Type"), "Should not content type") + XCTAssertTrue(res.testable.has(contentLength: 35), "Wrong content length") + XCTAssertTrue(res.testable.has(content: #"{"error":true,"reason":"Not Found"}"#), "Incorrect content") } }