Skip to content

Commit

Permalink
removing @testable
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Dec 18, 2020
1 parent 135d02e commit e93c058
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ DerivedData/

# End of https://www.gitignore.io/api/vapor
/Package.resolved
/.swiftpm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@_exported import Foundation
@_exported import Vapor
@_exported @testable import NIO
@_exported import NIO


extension TestableProperty where TestableType == HTTPRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Foundation
@testable import Vapor
@testable import NIO
import Vapor
import NIO


extension TestableProperty where TestableType: Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Foundation
@testable import Vapor
@testable import NIO
import Vapor
import NIO


extension TestableProperty where TestableType: Response {
Expand All @@ -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
}

}
6 changes: 3 additions & 3 deletions Tests/VaporTestToolsTests/AppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}

0 comments on commit e93c058

Please sign in to comment.