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

Code before:
        }
    }
    
    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)"
            let configuration = URLSessionConfiguration.background(withIdentifier: identifier)

            return Session(configuration: configuration)
        }()

        let urlString = "https://httpbin.org/post"
        let french = Data("français".utf8)
        let japanese = Data("日本語".utf8)

        let expectation = self.expectation(description: "multipart form data upload should succeed")

        var request: URLRequest?
        var response: HTTPURLResponse?
        var data: Data?
        var error: AFError?

        // When

Review comment (suggestion):
```suggestion
        XCTAssertNil(request.uploadable)
```

Since the `uploadable` value isn't being used it can just be checked inline.

Code after:
        }
    }

    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)

            return Session(configuration: configuration)
        }()

        let urlString = "https://httpbin.org/post"
        let french = Data("français".utf8)
        let japanese = Data("日本語".utf8)

        let expectation = self.expectation(description: "multipart form data upload should succeed")

        var request: URLRequest?
        var response: HTTPURLResponse?
        var data: Data?
        var error: AFError?

        // When
        let upload = manager.upload(multipartFormData: { multipartFormData in