Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Work around SwiftPM's inability for fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dduan committed Sep 22, 2018
1 parent fa7401c commit c2faf16
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions Tests/JustTests/JustTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ final class JustSendingJSON: XCTestCase {
}

final class JustSendingFiles: XCTestCase {
private var elonPhotoURL: URL {
let lastPathSegmentLength = #file.split(separator: "/").last!.count
let parentLength = #file.count - lastPathSegmentLength
let elonPhotoPath = String(#file.prefix(parentLength)) + "elon.jpg"
return URL(fileURLWithPath: elonPhotoPath)
}

func testNotIncludeMultipartHeaderForEmptyFiles() {
let r = Just.post("http://httpbin.org/post", files: [: ])
XCTAssertNotNil(r.json)
Expand All @@ -293,27 +300,18 @@ final class JustSendingFiles: XCTestCase {
}

func testSendingAFileSpecifiedByURLWithoutMimetype() {
if let elonPhotoURL = Bundle(for: JustSendingFiles.self)
.url(forResource: "elon", withExtension: "jpg")
{
let r = Just.post("http://httpbin.org/post",
files: ["elon": .url(elonPhotoURL, nil)])
XCTAssertNotNil(r.json)
if let data = r.json as? [String: Any] {
XCTAssertNotNil(data["files"])
if let files = data["files"] as? [String: String] {
XCTAssertNotNil(files["elon"])
}
let r = Just.post("http://httpbin.org/post",
files: ["elon": .url(elonPhotoURL, nil)])
XCTAssertNotNil(r.json)
if let data = r.json as? [String: Any] {
XCTAssertNotNil(data["files"])
if let files = data["files"] as? [String: String] {
XCTAssertNotNil(files["elon"])
}
} else {
XCTFail("resource needed for this test can't be found")
}
}

func testSendingAFileSpecifiedByURLWithMimetype() {
if let elonPhotoURL = Bundle(for: JustSendingFiles.self)
.url(forResource: "elon", withExtension: "jpg")
{
let r = Just.post("http://httpbin.org/post",
files: ["elon": .url(elonPhotoURL, "image/jpeg")])
XCTAssertNotNil(r.json)
Expand All @@ -323,9 +321,6 @@ final class JustSendingFiles: XCTestCase {
XCTAssertNotNil(files["elon"])
}
}
} else {
XCTFail("resource needed for this test can't be found")
}
}

func testSendingAFileSpecifiedByDataWithoutMimetype() {
Expand Down

0 comments on commit c2faf16

Please sign in to comment.