test: fix flaky tests

This commit is contained in:
Steven Arcangeli 2023-11-19 19:40:20 -08:00
parent af04969c43
commit 4df43ad5f5
5 changed files with 31 additions and 21 deletions

View file

@ -20,17 +20,23 @@ end
a.describe("freedesktop", function()
local tmpdir
local tmphome
local home = vim.env.XDG_DATA_HOME
a.before_each(function()
require("oil.config").delete_to_trash = true
tmpdir = TmpDir.new()
tmphome = TmpDir.new()
package.loaded["oil.adapters.trash"] = require("oil.adapters.trash.freedesktop")
local trash_dir = string.format(".Trash-%d", uv.getuid())
tmpdir:create({ fs.join(trash_dir, "__dummy__") })
vim.env.XDG_DATA_HOME = tmphome.path
end)
a.after_each(function()
vim.env.XDG_DATA_HOME = home
if tmpdir then
tmpdir:dispose()
end
if tmphome then
tmphome:dispose()
end
test_util.reset_editor()
package.loaded["oil.adapters.trash"] = nil
end)
@ -140,12 +146,8 @@ a.describe("freedesktop", function()
test_util.actions.save()
test_util.actions.reload()
assert.are.same({ "a.txt" }, parse_entries(0))
local uid = uv.getuid()
tmpdir:assert_fs({
["a.txt"] = "a.txt",
[".Trash-" .. uid .. "/__dummy__"] = ".Trash-" .. uid .. "/__dummy__",
[".Trash-" .. uid .. "/files/"] = true,
[".Trash-" .. uid .. "/info/"] = true,
})
end)