You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.1 KiB
26 lines
1.1 KiB
import Foundation
|
|
import Testing
|
|
@testable import Music
|
|
|
|
// Verifies the shared file-stat helper reads size/mod-date from disk and
|
|
// produces a fileHash identical to Track.computeHash (the existing canonical formula).
|
|
struct TrackFileStatsTests {
|
|
@Test func compute_matchesTrackComputeHash() throws {
|
|
// Step 1: write a temp file with known bytes.
|
|
let url = URL(fileURLWithPath: NSTemporaryDirectory())
|
|
.appendingPathComponent(UUID().uuidString + ".bin")
|
|
try Data(repeating: 0xAB, count: 1234).write(to: url)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
// Step 2: compute stats via the helper.
|
|
let stats = try TrackFileStats.compute(for: url)
|
|
|
|
// Step 3: independently read attrs and assert the helper agrees.
|
|
let attrs = try FileManager.default.attributesOfItem(atPath: url.path)
|
|
let size = attrs[.size] as? Int64 ?? -1
|
|
let mod = attrs[.modificationDate] as? Date ?? Date.distantPast
|
|
#expect(stats.fileSize == size)
|
|
#expect(stats.dateModified == mod)
|
|
#expect(stats.fileHash == Track.computeHash(fileSize: size, modificationDate: mod))
|
|
}
|
|
}
|
|
|