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
@@ -413,6 +413,11 @@ final class BugfixTests: XCTestCase {
|
||||
XCTAssertTrue(lib.sets.first?.enabled ?? false)
|
||||
}
|
||||
|
||||
func testDateOnlyUpdateClearsIIMTimeCreated() {
|
||||
let arguments = MetadataWriter.dateArguments("2026-11-03", writeIIM: true)
|
||||
XCTAssertTrue(arguments.contains("-IPTC:TimeCreated="))
|
||||
}
|
||||
|
||||
func testDateCreatedKeepsTimeOfDay() {
|
||||
var item = PhotoItem(primary: URL(fileURLWithPath: "/x/a.jpg"))
|
||||
item.apply(fileMeta: ["XMP-photoshop:DateCreated": .string("2026:11:02 18:31:05+01:00")], sidecarMeta: nil)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
import XCTest
|
||||
@testable import LichtkastenCore
|
||||
|
||||
final class DeliveryTests: XCTestCase {
|
||||
func testMinimumEdgeUsesTheFileOnDisk() throws {
|
||||
let file = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString + ".png")
|
||||
let image = try XCTUnwrap(Data(base64Encoded: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jS0sAAAAASUVORK5CYII="))
|
||||
try image.write(to: file)
|
||||
defer { try? FileManager.default.removeItem(at: file) }
|
||||
|
||||
var options = PreflightOptions()
|
||||
options.requiredFields = []
|
||||
options.minLongEdge = 2
|
||||
let issues = Preflight.check(iptc: IPTCValues(), exif: ["ImageWidth": "4000", "ImageHeight": "3000"],
|
||||
captureDate: nil, codes: CodeReplacements(), options: options,
|
||||
uploadFiles: [file])
|
||||
XCTAssertEqual(issues.count, 1)
|
||||
XCTAssertEqual(issues.first?.severity, .error)
|
||||
XCTAssertTrue(issues.first?.message.contains("1 px") == true)
|
||||
}
|
||||
|
||||
func testExportResultKeepsOriginalPathForEachJPEG() {
|
||||
let result = LightroomJobResult.parse("""
|
||||
exported=/sent/DSC_0001-2.jpg
|
||||
source=/raw/DSC_0001-2.nef
|
||||
exported=/sent/DSC_0001-3.jpg
|
||||
source=/raw/DSC_0001.nef
|
||||
exported=/sent/legacy.jpg
|
||||
""")
|
||||
XCTAssertEqual(result.exportSources[URL(fileURLWithPath: "/sent/DSC_0001-2.jpg")]?.path,
|
||||
"/raw/DSC_0001-2.nef")
|
||||
XCTAssertEqual(result.exportSources[URL(fileURLWithPath: "/sent/DSC_0001-3.jpg")]?.path,
|
||||
"/raw/DSC_0001.nef")
|
||||
XCTAssertNil(result.exportSources[URL(fileURLWithPath: "/sent/legacy.jpg")])
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import Foundation
|
||||
import XCTest
|
||||
@testable import LichtkastenCore
|
||||
|
||||
final class IngestRecoveryTests: XCTestCase {
|
||||
private func fixture() throws -> (root: URL, source: URL, primary: URL, backup: URL) {
|
||||
let fm = FileManager.default
|
||||
let root = fm.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
|
||||
let source = root.appendingPathComponent("card", isDirectory: true)
|
||||
let primary = root.appendingPathComponent("primary", isDirectory: true)
|
||||
let backup = root.appendingPathComponent("backup", isDirectory: true)
|
||||
for dir in [source, primary, backup] { try fm.createDirectory(at: dir, withIntermediateDirectories: true) }
|
||||
addTeardownBlock { try fm.removeItem(at: root) }
|
||||
return (root, source, primary, backup)
|
||||
}
|
||||
|
||||
func testEqualSizeDoesNotIdentifyDuplicate() throws {
|
||||
let dirs = try fixture()
|
||||
let src = dirs.source.appendingPathComponent("DSC_0001.NEF")
|
||||
try Data([1, 2]).write(to: src)
|
||||
try Data([2, 1]).write(to: dirs.primary.appendingPathComponent(src.lastPathComponent))
|
||||
let result = IngestService.uniqueName("DSC_0001", files: [src], in: dirs.primary, skipDuplicates: true)
|
||||
XCTAssertEqual(result.name, "DSC_0001-1")
|
||||
XCTAssertFalse(result.skip)
|
||||
}
|
||||
|
||||
func testMissingRecursiveSourceThrows() throws {
|
||||
let dirs = try fixture()
|
||||
XCTAssertThrowsError(try FolderScanner.scan(folder: dirs.root.appendingPathComponent("missing"), recursive: true))
|
||||
}
|
||||
|
||||
func testRetryFillsBackupWhenPrimaryAlreadyExists() async throws {
|
||||
let dirs = try fixture()
|
||||
let src = try makePhoto(in: dirs.source)
|
||||
try FileManager.default.copyItem(at: src, to: dirs.primary.appendingPathComponent(src.lastPathComponent))
|
||||
|
||||
try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup)
|
||||
|
||||
XCTAssertEqual(try Data(contentsOf: dirs.backup.appendingPathComponent(src.lastPathComponent)), try Data(contentsOf: src))
|
||||
}
|
||||
|
||||
func testBackupNameCollisionAllocatesSameNewNameInBothDestinations() async throws {
|
||||
let dirs = try fixture()
|
||||
let src = try makePhoto(in: dirs.source)
|
||||
let unrelated = Data("unrelated backup".utf8)
|
||||
let existing = dirs.backup.appendingPathComponent(src.lastPathComponent)
|
||||
try unrelated.write(to: existing)
|
||||
|
||||
try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup)
|
||||
|
||||
XCTAssertEqual(try Data(contentsOf: existing), unrelated)
|
||||
for dir in [dirs.primary, dirs.backup] {
|
||||
XCTAssertEqual(try Data(contentsOf: dir.appendingPathComponent("photo-1.png")), try Data(contentsOf: src))
|
||||
}
|
||||
}
|
||||
|
||||
func testIncrementalRepairsMissingBackupAndPreservesEditedPrimary() async throws {
|
||||
let dirs = try fixture()
|
||||
let src = try makePhoto(in: dirs.source)
|
||||
let history = dirs.root.appendingPathComponent("history.json")
|
||||
let primary = dirs.primary.appendingPathComponent("photo-4.png")
|
||||
let backup = dirs.backup.appendingPathComponent("photo-4.png")
|
||||
_ = try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup, history: history, sequence: 4)
|
||||
let edited = Data("edited primary".utf8)
|
||||
try edited.write(to: primary)
|
||||
|
||||
let complete = try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup, history: history, sequence: 5)
|
||||
XCTAssertEqual(complete.skipped, 1)
|
||||
try FileManager.default.removeItem(at: backup)
|
||||
_ = try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup, history: history, sequence: 5)
|
||||
|
||||
XCTAssertEqual(try Data(contentsOf: primary), edited)
|
||||
XCTAssertEqual(try Data(contentsOf: backup), try Data(contentsOf: src))
|
||||
XCTAssertFalse(FileManager.default.fileExists(atPath: dirs.primary.appendingPathComponent("photo-5.png").path))
|
||||
}
|
||||
|
||||
func testIncrementalDoesNotAcceptReplacedBackup() async throws {
|
||||
let dirs = try fixture()
|
||||
let src = try makePhoto(in: dirs.source)
|
||||
let history = dirs.root.appendingPathComponent("history.json")
|
||||
_ = try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup, history: history, sequence: 4)
|
||||
let previousBackup = dirs.backup.appendingPathComponent("photo-4.png")
|
||||
let unrelated = Data(repeating: 1, count: try Data(contentsOf: src).count)
|
||||
try unrelated.write(to: previousBackup)
|
||||
|
||||
_ = try await ingest(source: dirs.source, primary: dirs.primary, backup: dirs.backup, history: history, sequence: 5)
|
||||
|
||||
XCTAssertEqual(try Data(contentsOf: previousBackup), unrelated)
|
||||
for dir in [dirs.primary, dirs.backup] {
|
||||
XCTAssertEqual(try Data(contentsOf: dir.appendingPathComponent("photo-4-1.png")), try Data(contentsOf: src))
|
||||
}
|
||||
}
|
||||
|
||||
private func makePhoto(in source: URL) throws -> URL {
|
||||
let png = try XCTUnwrap(Data(base64Encoded: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jP1sAAAAASUVORK5CYII="))
|
||||
let photo = source.appendingPathComponent("photo.png")
|
||||
try png.write(to: photo)
|
||||
return photo
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func ingest(source: URL, primary: URL, backup: URL, history: URL? = nil, sequence: Int? = nil) async throws -> IngestResult {
|
||||
guard let exe = ExifTool.locate() else { throw XCTSkip("ExifTool fehlt") }
|
||||
var settings = IngestSettings()
|
||||
settings.primaryDestination = primary.path
|
||||
settings.backupDestination = backup.path
|
||||
settings.secondaryEnabled = true
|
||||
settings.incremental = history != nil
|
||||
settings.folderPattern = ""
|
||||
if let sequence {
|
||||
settings.startSequence = sequence
|
||||
settings.renamePattern = "photo-{seqn}"
|
||||
}
|
||||
return try await IngestService.run(sources: [source], settings: settings,
|
||||
exiftool: ExifTool(executable: exe), historyFile: history) { _ in }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user