Implement watching a path
Each inotify instance produces events for paths in its watch list. Each item in the watch list is identified by its watch descriptor. Different paths can be watched for different events.
This commit is contained in:
10
Tests/InotifyIntegrationTests/Utilities.swift
Normal file
10
Tests/InotifyIntegrationTests/Utilities.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
|
||||
func withTempDir(_ body: (String) async throws -> Void) async throws {
|
||||
let dir = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("InotifyIntegrationTests-\(UUID().uuidString)")
|
||||
.path
|
||||
try FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(atPath: dir) }
|
||||
try await body(dir)
|
||||
}
|
||||
21
Tests/InotifyIntegrationTests/WatchTests.swift
Normal file
21
Tests/InotifyIntegrationTests/WatchTests.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import Inotify
|
||||
|
||||
@Suite("Watch Management")
|
||||
struct WatchTests {
|
||||
@Test func addWatchReturnsValidDescriptor() async throws {
|
||||
try await withTempDir { dir in
|
||||
let watcher = try Inotify()
|
||||
let wd = try await watcher.addWatch(path: dir, mask: .allEvents)
|
||||
#expect(wd >= 0)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func addWatchOnInvalidPathThrows() async throws {
|
||||
let watcher = try Inotify()
|
||||
await #expect(throws: InotifyError.self) {
|
||||
try await watcher.addWatch(path: "/nonexistent-\(UUID())", mask: .allEvents)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user