2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-21 15:18:19 +00:00

test(xcat-core): go-xcat complete uninstall skips packages with config files left

After `apt-get remove`, dpkg reports a package as "deinstall ok
config-files". uninstall_xcat_completely() selects packages with
installed_packages(), which accepts only "install ok installed". A
complete uninstall after an ordinary uninstall therefore does not purge
the xCAT packages, and their configuration files stay on the node.

The new bats test runs both uninstall paths against a dpkg-query stub.
The two purge tests fail on this tree. The ordinary uninstall keeps its
installed-only filter.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-09-28 14:55:50 -03:00
parent 5a66b20aea
commit a69debb41b
@@ -0,0 +1,67 @@
#!/usr/bin/env bats
#
# `apt-get remove` leaves a package in the "deinstall ok config-files" state (dpkg `rc`).
# `go-xcat uninstall` removes, so it skips those. `go-xcat uninstall --completely` purges,
# so it must include them, or a remove followed by a complete uninstall leaves the
# configuration files behind.
#
# go-xcat is sourced. dpkg-query and the package, kill and trash steps are shell functions
# here, and PATH is empty, so no test reads or changes the host package database or files.
load 'helpers/go_xcat'
setup()
{
go_xcat_require_source
# shellcheck disable=SC1090
source "$GO_XCAT_SOURCE"
remove_package() { printf 'remove %s\n' "$@"; }
purge_package() { printf 'purge %s\n' "$@"; }
kill_xcat() { :; }
trash_xcat() { :; }
# The state dpkg reports after `apt-get remove xcat-test-removed`.
dpkg-query()
{
case "$3" in
xcat-test-installed) printf 'install ok installed' ;;
xcat-test-removed) printf 'deinstall ok config-files' ;;
*) return 1 ;;
esac
}
GO_XCAT_UNINSTALL_LIST=(xcat-test-absent xcat-test-installed xcat-test-removed)
}
without_path()
{
local PATH=""
"$@"
}
@test "deb: complete uninstall purges packages that only have configuration files left" {
run without_path uninstall_xcat_completely
[ "$status" -eq 0 ]
[ "$output" = "purge -y
purge xcat-test-installed
purge xcat-test-removed" ]
}
@test "deb: complete uninstall after a remove purges the removed package" {
GO_XCAT_UNINSTALL_LIST=(xcat-test-absent xcat-test-removed)
run without_path uninstall_xcat_completely
[ "$status" -eq 0 ]
[ "$output" = "purge -y
purge xcat-test-removed" ]
}
@test "deb: ordinary uninstall removes only the installed packages" {
run without_path uninstall_xcat -y
[ "$status" -eq 0 ]
[ "$output" = "remove -y
remove xcat-test-installed" ]
}
@test "deb: a package with only configuration files left is not reported as installed" {
run without_path installed_packages xcat-test-removed xcat-test-installed
[ "$status" -eq 0 ]
[ "$output" = "xcat-test-installed" ]
}