Commit 521b185b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

pkg: Tests for file collisions detection

parent c92df412
......@@ -420,12 +420,12 @@ function collision_check(current_status, remove_pkgs, add_pkgs)
for name, status in pairs(current_status) do
if remove_pkgs[name] then
-- If we remove the package, all its files might disappear
for f in pairs(status.file) do
for f in pairs(status.files or {}) do
remove_candidates[f] = true
end
else
-- Otherwise, the file is in the OS
for f in pairs(status.files) do
for f in pairs(status.files or {}) do
file_insert(f, name, 'existing')
end
end
......
......@@ -312,6 +312,66 @@ function test_pkg_unpack()
}, conffiles)
end
-- Test the collision_check function
function test_collisions()
local status = B.status_parse()
-- Just remove a package - no collisions, but files should disappear
local col, rem = B.collision_check(status, {['kmod-usb-storage'] = true}, {})
assert_table_equal({}, col)
assert_table_equal({
["/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko"] = true,
["/etc/modules-boot.d/usb-storage"] = true,
["/etc/modules.d/usb-storage"] = true
}, rem)
-- Add a new package, but without any collisions
local col, rem = B.collision_check(status, {}, {
['package'] = {
['/a/file'] = true
}
})
assert_table_equal({}, col)
assert_table_equal({}, rem)
local test_pkg = {
['package'] = {
["/etc/modules.d/usb-storage"] = true
}
}
-- Add a new package, collision isn't reported, because the original package owning it gets removed
local col, rem = B.collision_check(status, {['kmod-usb-storage'] = true}, test_pkg)
assert_table_equal({}, col)
assert_table_equal({
["/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko"] = true,
["/etc/modules-boot.d/usb-storage"] = true
-- The usb-storage file is taken over, it doesn't disappear
}, rem)
-- A collision
local col, rem = B.collision_check(status, {}, test_pkg)
-- We need to do the check in two parts, we don't have a deep table compare (maybe we should?)
assert_table_equal({
["/etc/modules.d/usb-storage"] = true
}, utils.map(col, function (k) return k, true end))
assert_table_equal({
["kmod-usb-storage"] = "existing",
["package"] = "new"
}, col["/etc/modules.d/usb-storage"])
assert_table_equal({}, rem)
-- A collision between two new packages
test_pkg['another'] = test_pkg['package']
local col, rem = B.collision_check(status, {['kmod-usb-storage'] = true}, test_pkg)
assert_not_equal({
["/etc/modules.d/usb-storage"] = true
}, utils.map(col, function (k) return k, true end))
assert_table_equal({
["package"] = "new",
["another"] = "new"
}, col["/etc/modules.d/usb-storage"])
assert_table_equal({
["/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko"] = true,
["/etc/modules-boot.d/usb-storage"] = true
-- The usb-storage file is taken over, it doesn't disappear
}, rem)
end
function setup()
local sdir = os.getenv("S") or "."
-- Use a shortened version of a real status file for tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment