Kartenimport, Metadaten und Versand absichern
This commit is contained in:
1 parent
be6bd49da5
commit
427b6fa7b0
18 files changed
+643
-193
No files matched your search
@@ -0,0 +1,38 @@
|
||||
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")
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user