Commit ffbc3ad5 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

pkg: Tests can compare tables recursively

parent ac569cb5
......@@ -139,20 +139,9 @@ end
-- Tests for status_parse ‒ which parses the whole thing
function test_status_parse()
local result = B.status_parse()
local function status_check(name, desc, depends, status, files, conffiles)
local function status_check(name, desc)
local pkg = result[name]
assert_not_nil(pkg)
local function sub_check(value, name)
if value then
assert_not_nil(pkg[name])
assert_table_equal(value, pkg[name])
desc[name] = pkg[name]
end
end
sub_check(depends, "Depends")
sub_check(status, "Status")
sub_check(files, "files")
sub_check(conffiles, "Conffiles")
assert_table_equal(desc, pkg)
end
local std_status = {install = true, user = true, installed = true}
......@@ -165,15 +154,18 @@ function test_status_parse()
Section = "kernel",
["Installed-Size"] = "22537",
Description = "Kernel support for USB Mass Storage devices",
["Installed-Time"] = "1453896142"
}, {
"kernel (=3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10)",
"kmod-scsi-core",
"kmod-usb-core"
}, std_status, {
["/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko"] = true,
["/etc/modules-boot.d/usb-storage"] = true,
["/etc/modules.d/usb-storage"] = true
["Installed-Time"] = "1453896142",
Depends = {
"kernel (=3.18.21-1-70ea6b9a4b789c558ac9d579b5c1022f-10)",
"kmod-scsi-core",
"kmod-usb-core"
},
Status = std_status,
files = {
["/lib/modules/3.18.21-70ea6b9a4b789c558ac9d579b5c1022f-10/usb-storage.ko"] = true,
["/etc/modules-boot.d/usb-storage"] = true,
["/etc/modules.d/usb-storage"] = true
}
})
status_check("terminfo", {
Package = "terminfo",
......@@ -185,19 +177,22 @@ function test_status_parse()
Section = "libs",
["Installed-Size"] = "5822",
Description = "Terminal Info Database (ncurses)",
["Installed-Time"] = "1453896265"
}, {"libc"}, std_status, {
["/usr/share/terminfo/x/xterm"] = true,
["/usr/share/terminfo/r/rxvt-unicode"] = true,
["/usr/share/terminfo/d/dumb"] = true,
["/usr/share/terminfo/a/ansi"] = true,
["/usr/share/terminfo/x/xterm-color"] = true,
["/usr/share/terminfo/r/rxvt"] = true,
["/usr/share/terminfo/s/screen"] = true,
["/usr/share/terminfo/x/xterm-256color"] = true,
["/usr/share/terminfo/l/linux"] = true,
["/usr/share/terminfo/v/vt100"] = true,
["/usr/share/terminfo/v/vt102"] = true
["Installed-Time"] = "1453896265",
Depends = {"libc"},
Status = std_status,
files = {
["/usr/share/terminfo/x/xterm"] = true,
["/usr/share/terminfo/r/rxvt-unicode"] = true,
["/usr/share/terminfo/d/dumb"] = true,
["/usr/share/terminfo/a/ansi"] = true,
["/usr/share/terminfo/x/xterm-color"] = true,
["/usr/share/terminfo/r/rxvt"] = true,
["/usr/share/terminfo/s/screen"] = true,
["/usr/share/terminfo/x/xterm-256color"] = true,
["/usr/share/terminfo/l/linux"] = true,
["/usr/share/terminfo/v/vt100"] = true,
["/usr/share/terminfo/v/vt102"] = true
}
})
status_check("dnsmasq-dhcpv6", {
Package = "dnsmasq-dhcpv6",
......@@ -211,24 +206,31 @@ function test_status_parse()
Description = [[It is intended to provide coupled DNS and DHCP service to a LAN.
This is a variant with DHCPv6 support]],
["Installed-Time"] = "1453896240"
}, {"libc"}, std_status, {
["/etc/dnsmasq.conf"] = true,
["/etc/hotplug.d/iface/25-dnsmasq"] = true,
["/etc/config/dhcp"] = true,
["/etc/init.d/dnsmasq"] = true,
["/usr/sbin/dnsmasq"] = true
}, {
["/etc/config/dhcp"] = "f81fe9bd228dede2165be71e5c9dcf76cc",
["/etc/dnsmasq.conf"] = "1e6ab19c1ae5e70d609ac7b6246541d520"
["Installed-Time"] = "1453896240",
Depends = {"libc"},
Status = std_status,
files = {
["/etc/dnsmasq.conf"] = true,
["/etc/hotplug.d/iface/25-dnsmasq"] = true,
["/etc/config/dhcp"] = true,
["/etc/init.d/dnsmasq"] = true,
["/usr/sbin/dnsmasq"] = true
},
Conffiles = {
["/etc/config/dhcp"] = "f81fe9bd228dede2165be71e5c9dcf76cc",
["/etc/dnsmasq.conf"] = "1e6ab19c1ae5e70d609ac7b6246541d520"
}
})
-- Slightly broken package ‒ no relevant info files
status_check("ucollect-count", {
Package = "ucollect-count",
Version = "27",
Architecture = "mpc85xx",
["Installed-Time"] = "1453896279"
}, {"libc", "ucollect-prog"}, std_status, {})
["Installed-Time"] = "1453896279",
Depends = {"libc", "ucollect-prog"},
Status = std_status,
files = {}
})
-- More broken case - the whole status file missing
B.status_file = "/does/not/exist"
assert_error(B.status_parse)
......@@ -346,14 +348,12 @@ function test_collisions()
}, 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"])
["/etc/modules.d/usb-storage"] = {
["kmod-usb-storage"] = "existing",
["package"] = "new"
}
}, col)
assert_table_equal({}, rem)
-- A collision between two new packages
test_pkg['another'] = test_pkg['package']
......
......@@ -6,13 +6,28 @@ function launch(test)
end
function assert_table_equal(t1, t2)
if t1 == t2 then
-- The exact same instance
return
end
lunit.assert_table(t1)
lunit.assert_table(t2)
local function cmp(t1, t2, name)
for k, v in pairs(t1) do
lunit.assert_equal(v, t2[k], "Values for key '" .. k .. "' differ, " .. name)
local v2 = t2[k]
if type(v) ~= "table" or type(v2) ~= "table" then
-- In case of two tables, we have special comparison below
lunit.assert_equal(v, v2, "Values for key '" .. k .. "' differ, " .. name)
end
end
end
cmp(t1, t2, " pass 1")
cmp(t2, t1, " pass 2")
-- Recurse into sub-tables
for k, v in pairs(t1) do
local v2 = t2[k]
if type(v) == "table" and type(v2) == "table" then
assert_table_equal(v, v2)
end
end
end
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