Repository: Alamofire/Alamofire
File: Tests/UploadTests.swift (Swift)

Code before:
        waitForExpectations(timeout: timeout, handler: nil)

        // Then
        guard let uploadable = request.uploadable, case .file = uploadable else {
            XCTFail("Uploadable is not .file")
            return
        }

        XCTAssertTrue(response?.result.isSuccess == true)

        if
            let request = response?.request,
            let multipartFormData = formData,
            let contentType = request.value(forHTTPHeaderField: "Content-Type") {
            XCTAssertEqual(contentType, multipartFormData.contentType, "Content-Type header value should match")
        } else {
            XCTFail("Content-Type header value should not be nil")
        }
    }
    
    func testThatUploadingMultipartFormDataWithNotExistFileShouldFail() {
        // Given
        let urlString = "https://httpbin.org/post"
        let imageURL = URL(string: "file://not_exists_file.jpg")!

        let expectation = self.expectation(description: "multipart form data upload with wrong file should fail")
        var response: DataResponse<Data?, AFError>?

        // When
        let request = AF.upload(multipartFormData: { multipartFormData in
            multipartFormData.append(imageURL, withName: "upload_file")
        },
                                to: urlString,
                                usingThreshold: 0).response { resp in
            response = resp
            expectation.fulfill()
        }

        waitForExpectations(timeout: timeout, handler: nil)

        // Then
        let uploadable = request.uploadable
        XCTAssertNil(uploadable)
        XCTAssertTrue(response?.result.isSuccess == false)
    }

    #if os(macOS)
    func disabled_testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
        // Given
        let manager: Session = {
            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"

Review comment (bug):
```suggestion
        let expectation = self.expectation(description: "multipart form data upload from nonexistent file should fail")
```

Again, this can be made a bit easier to read.

Code after:
        waitForExpectations(timeout: timeout, handler: nil)

        // Then
        guard let uploadable = request.uploadable, case .file = uploadable else {
            XCTFail("Uploadable is not .file")
            return
        }

        XCTAssertTrue(response?.result.isSuccess == true)

        if
            let request = response?.request,
            let multipartFormData = formData,
            let contentType = request.value(forHTTPHeaderField: "Content-Type") {
            XCTAssertEqual(contentType, multipartFormData.contentType, "Content-Type header value should match")
        } else {
            XCTFail("Content-Type header value should not be nil")
        }
    }

    func testThatUploadingMultipartFormDataWithNonexistentFileThrowsAnError() {
        // Given
        let urlString = URL.makeHTTPBinURL(path: "post")
        let imageURL = URL(fileURLWithPath: "does_not_exist.jpg")

        let expectation = self.expectation(description: "multipart form data upload from nonexistent file should fail")
        var response: DataResponse<Data?, AFError>?

        // When
        let request = AF.upload(multipartFormData: { multipartFormData in
                                    multipartFormData.append(imageURL, withName: "upload_file")
                                },
                                to: urlString,
                                usingThreshold: 0).response { resp in
            response = resp
            expectation.fulfill()
        }

        waitForExpectations(timeout: timeout)

        // Then
        XCTAssertNil(request.uploadable)
        XCTAssertTrue(response?.result.isSuccess == false)
    }

    #if os(macOS)
    func disabled_testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
        // Given
        let manager: Session = {
            let identifier = "org.alamofire.uploadtests.\(UUID().uuidString)"
            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)