import Foundation @testable import LichtkastenCore import XCTest final class FTPUploaderTests: XCTestCase { func testExistingRemoteFileStopsUpload() async throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) defer { try? FileManager.default.removeItem(at: directory) } let curl = directory.appendingPathComponent("curl") let uploaded = directory.appendingPathComponent("uploaded") let script = """ #!/bin/sh for arg do if [ "$arg" = "MLSD" ]; then printf '%s\\r\\n' 'type=file; other.jpg' 'type=OS.unix=slink; PHOTO.jpg' exit 0 fi done touch '\(uploaded.path)' """ try script.write(to: curl, atomically: true, encoding: .utf8) try FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: curl.path) let uploader = FTPUploader(curlExecutable: curl.path) let destination = FTPDestination(host: "example.test", replaceExisting: false) let photo = directory.appendingPathComponent("photo.jpg") try Data([0]).write(to: photo) do { try await uploader.upload(file: photo, to: destination, password: nil) XCTFail("An existing remote filename should stop the upload") } catch UploadError.remoteNameConflict(let name) { XCTAssertEqual(name, "photo.jpg") } XCTAssertFalse(FileManager.default.fileExists(atPath: uploaded.path)) } }