Repository: Moya/Moya
File: Tests/TestHelpers.swift (Swift)

Code before:
    }
    public var task: Task {
        switch self {
        case .downloadMoyaWebContent:
            return .downloadDestination(defaultDownloadDestination)
        case .requestMoyaWebContent:
            return .requestPlain
        }
    }
    public var sampleData: Data {
        switch self {
        case .downloadMoyaWebContent, .requestMoyaWebContent:
            return Data(count: 4000)
        }
    }

    public var headers: [String: String]? {
        return nil
    }
}

// MARK: - Upload Multipart Helpers

extension HTTPBin {
    static func createMultipartFormData() -> [MultipartFormData] {
        let url = Bundle(for: MoyaProviderSpec.self).url(forResource: "testImage", withExtension: "png")!
        let string = "some data"
        guard let data = string.data(using: .utf8) else { fatalError("Failed creating Data from String \(string)") }
        return [
            MultipartFormData(provider: .file(url), name: "file", fileName: "testImage"),
            MultipartFormData(provider: .data(data), name: "data")
        ]
    }
}

// MARK: - String Helpers
extension String {
    var urlEscaped: String {
        return self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
    }
}

// MARK: - DispatchQueue Test Helpers
// https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160613/002280.html
extension DispatchQueue {
    class var currentLabel: String? {
        return String(validatingUTF8: __dispatch_queue_get_label(nil))
    }
}

private let defaultDownloadDestination: DownloadDestination = { temporaryURL, response in

Review comment (refactor):
I know it's a helper, but maybe `fatalError` here too?

Code after:
    }
    public var task: Task {
        switch self {
        case .downloadMoyaWebContent:
            return .downloadDestination(defaultDownloadDestination)
        case .requestMoyaWebContent:
            return .requestPlain
        }
    }
    public var sampleData: Data {
        switch self {
        case .downloadMoyaWebContent, .requestMoyaWebContent:
            return Data(count: 4000)
        }
    }

    public var headers: [String: String]? {
        return nil
    }
}

// MARK: - Upload Multipart Helpers

extension HTTPBin {
    static func createTestMultipartFormData() -> [MultipartFormData] {
        guard let url = Bundle(for: MoyaProviderSpec.self).url(forResource: "testImage", withExtension: "png") else {
            fatalError("Resource testImage.png could not be found in bundle")
        }
        let string = "some data"
        guard let data = string.data(using: .utf8) else {
            fatalError("Failed creating Data from String \(string)")
        }
        return [
            MultipartFormData(provider: .file(url), name: "file", fileName: "testImage"),
            MultipartFormData(provider: .data(data), name: "data")
        ]
    }
}

// MARK: - String Helpers
extension String {
    var urlEscaped: String {
        return self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
    }
}

// MARK: - DispatchQueue Test Helpers
// https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160613/002280.html
extension DispatchQueue {
    class var currentLabel: String? {
        return String(validatingUTF8: __dispatch_queue_get_label(nil))