test: add a test for deleted sub dirs

This commit is contained in:
CJ van den Berg 2026-03-29 12:47:21 +02:00
parent 4e594c3542
commit 8be60c0688
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -300,6 +300,35 @@ fn testCreateSubdir(comptime Watcher: type, allocator: std.mem.Allocator) !void
try std.testing.expect(th.hasChange(dir_path, .created, .dir));
}
fn testDeleteSubdir(comptime Watcher: type, allocator: std.mem.Allocator) !void {
const TH = MakeTestHandler(Watcher);
const tmp = try makeTempDir(allocator);
defer {
removeTempDir(tmp);
allocator.free(tmp);
}
const th = try TH.init(allocator);
defer th.deinit();
const dir_path = try std.fs.path.join(allocator, &.{ tmp, "subdir" });
defer allocator.free(dir_path);
try std.fs.makeDirAbsolute(dir_path);
var watcher = try Watcher.init(allocator, &th.handler);
defer watcher.deinit();
try watcher.watch(tmp);
try drainEvents(Watcher, &watcher);
try std.fs.deleteDirAbsolute(dir_path);
try drainEvents(Watcher, &watcher);
try std.testing.expect(th.hasChange(dir_path, .deleted, .dir));
}
fn testRenameFile(comptime Watcher: type, allocator: std.mem.Allocator) !void {
const TH = MakeTestHandler(Watcher);
@ -555,6 +584,12 @@ test "deleting a file emits a 'deleted' event" {
}
}
test "deleting a dir emits a 'deleted' event" {
inline for (comptime std.enums.values(nw.Variant)) |variant| {
try testDeleteSubdir(nw.Create(variant), std.testing.allocator);
}
}
test "creating a sub-directory emits a 'created' event with object_type dir" {
inline for (comptime std.enums.values(nw.Variant)) |variant| {
try testCreateSubdir(nw.Create(variant), std.testing.allocator);