Skip to content

Commit 169eb09

Browse files
committed
Move the timestamp test
1 parent 79fab7f commit 169eb09

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

Tests/ContainerizationEXT4Tests/TestEXT4Format+Create.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,3 @@ struct Ext4FormatCreateTests {
7878
} // should create /parent automatically
7979
}
8080
}
81-
82-
@Suite(.serialized)
83-
struct NegativeTimestampRoundtripTests {
84-
private let fsPath = FilePath(
85-
FileManager.default.temporaryDirectory
86-
.appendingPathComponent("ext4-pre1970-roundtrip.img", isDirectory: false))
87-
private let apollo11MoonLanding: Date = {
88-
let f = ISO8601DateFormatter()
89-
f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
90-
return f.date(from: "1969-07-20T20:17:39.9Z")!
91-
}()
92-
93-
@Test func encodeNegativeTimestamp() throws {
94-
let formatter = try EXT4.Formatter(fsPath, minDiskSize: 32.kib())
95-
defer { try? formatter.close() }
96-
let ts = FileTimestamps(access: apollo11MoonLanding, modification: apollo11MoonLanding, creation: apollo11MoonLanding)
97-
try formatter.create(path: FilePath("/file"), mode: EXT4.Inode.Mode(.S_IFREG, 0o755), ts: ts, buf: nil)
98-
}
99-
100-
@Test func decodeNegativeTimestamp() throws {
101-
let reader = try EXT4.EXT4Reader(blockDevice: fsPath)
102-
let (_, inode) = try reader.stat(FilePath("/file"))
103-
let mtime = Date(fsTimestamp: UInt64(inode.mtime) | (UInt64(inode.mtimeExtra) << 32))
104-
let atime = Date(fsTimestamp: UInt64(inode.atime) | (UInt64(inode.atimeExtra) << 32))
105-
let crtime = Date(fsTimestamp: UInt64(inode.crtime) | (UInt64(inode.crtimeExtra) << 32))
106-
#expect(mtime == apollo11MoonLanding)
107-
#expect(atime == apollo11MoonLanding)
108-
#expect(crtime == apollo11MoonLanding)
109-
}
110-
}

Tests/ContainerizationEXT4Tests/TestEXT4Format.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,32 @@ struct Ext4FormatLinkTests {
244244
}
245245
}
246246

247+
@Suite(.serialized)
248+
struct NegativeTimestampRoundtripTests {
249+
private let fsPath = FilePath(
250+
FileManager.default.temporaryDirectory
251+
.appendingPathComponent("ext4-pre1970-roundtrip.img", isDirectory: false))
252+
private let apollo11MoonLanding: Date = {
253+
let f = ISO8601DateFormatter()
254+
f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
255+
return f.date(from: "1969-07-20T20:17:39.9Z")!
256+
}()
257+
258+
@Test func encodeNegativeTimestamp() throws {
259+
let formatter = try EXT4.Formatter(fsPath, minDiskSize: 32.kib())
260+
defer { try? formatter.close() }
261+
let ts = FileTimestamps(access: apollo11MoonLanding, modification: apollo11MoonLanding, creation: apollo11MoonLanding)
262+
try formatter.create(path: FilePath("/file"), mode: EXT4.Inode.Mode(.S_IFREG, 0o755), ts: ts, buf: nil)
263+
}
264+
265+
@Test func decodeNegativeTimestamp() throws {
266+
let reader = try EXT4.EXT4Reader(blockDevice: fsPath)
267+
let (_, inode) = try reader.stat(FilePath("/file"))
268+
let mtime = Date(fsTimestamp: UInt64(inode.mtime) | (UInt64(inode.mtimeExtra) << 32))
269+
let atime = Date(fsTimestamp: UInt64(inode.atime) | (UInt64(inode.atimeExtra) << 32))
270+
let crtime = Date(fsTimestamp: UInt64(inode.crtime) | (UInt64(inode.crtimeExtra) << 32))
271+
#expect(mtime == apollo11MoonLanding)
272+
#expect(atime == apollo11MoonLanding)
273+
#expect(crtime == apollo11MoonLanding)
274+
}
275+
}

0 commit comments

Comments
 (0)