2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-27 21:02:14 +00:00

test(go-xcat): cover the package table under a translated apt

Share the apt-cache double of the apt install tests. Check that
list_xcat_packages shows the apt candidates in the C locale and under a
translated apt.
This commit is contained in:
Vinícius Ferrão
2026-10-30 20:52:06 -03:00
parent 3d30d5fd86
commit 96850ce72b
3 changed files with 90 additions and 25 deletions
+3 -25
View File
@@ -5,44 +5,22 @@
# translated apt must not hide the packages that are there.
load 'helpers/go_xcat'
load 'helpers/go_xcat_apt'
setup()
{
go_xcat_require_source
}
# Run install_packages_apt with apt-cache and apt-get doubles. apt-get records its arguments.
# Run install_packages_apt with the apt-cache double. apt-get records its arguments.
#
# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and
# "nocandidate" is known with no candidate. apt-cache fails after it reports the
# package in APT_FAIL_AFTER.
# $@ Package names, answered as helpers/go_xcat_apt describes.
install_with_apt()
{
(
log="$BATS_TEST_TMPDIR/apt-get.log"
PATH=""
source "$GO_XCAT_SOURCE" || exit 70
apt-cache()
{
[ "$1" = policy ] || return 1
shift
local installed='Installed:' candidate='Candidate:' package
if [ "${LC_ALL:-${LANG:-}}" != C ]; then
installed='已安装:'
candidate='候选:'
fi
for package in "$@"; do
case " ${APT_UNKNOWN:-missing} " in
*" $package "*) continue ;;
esac
case "$package" in
nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;;
*) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \
"$package" "$installed" "$candidate" ;;
esac
[ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100
done
}
apt-get() { printf '%s\n' "$*" >>"$log"; }
install_packages_apt -y "$@"
)
@@ -0,0 +1,59 @@
#!/usr/bin/env bats
#
# go-xcat check, install and update print a table of the xCAT packages, with the installed version
# and the version that the repositories offer. On apt, the table must show the candidates that a
# translated apt reports.
load 'helpers/go_xcat'
load 'helpers/go_xcat_apt'
setup()
{
go_xcat_require_source
}
# Print the package table of list_xcat_packages with the apt-cache double. xcat-core offers xcat and
# xcat-server, xcat-dep offers ipmitool-xcat, and none of them is installed.
list_packages()
{
(
PATH=""
source "$GO_XCAT_SOURCE" || exit 70
get_package_list()
{
case "$1" in
xcat-core) echo xcat xcat-server ;;
xcat-dep) echo ipmitool-xcat ;;
esac
}
check_package_version()
{
local package
for package in "$@"; do
echo '(not installed)'
done
}
list_xcat_packages
)
}
# Succeed when the table offers version 1.0-1 of every package.
offers_every_package()
{
local package
for package in xcat xcat-server ipmitool-xcat; do
grep -Eq "^${package} +\\(not installed\\) +1\\.0-1 *\$" <<<"$1" || return 1
done
}
@test "the package table shows the apt candidates" {
LANG=C LC_ALL=C run list_packages
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
}
@test "the package table shows the candidates that a translated apt reports" {
LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 run list_packages
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
}
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Answer "apt-cache policy" as apt does, with translated labels unless LC_ALL or LANG is C.
#
# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and
# "nocandidate" is known with no candidate. apt-cache fails after it reports the
# package in APT_FAIL_AFTER.
apt-cache()
{
[ "$1" = policy ] || return 1
shift
local installed='Installed:' candidate='Candidate:' package
if [ "${LC_ALL:-${LANG:-}}" != C ]; then
installed='已安装:'
candidate='候选:'
fi
for package in "$@"; do
case " ${APT_UNKNOWN:-missing} " in
*" $package "*) continue ;;
esac
case "$package" in
nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;;
*) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \
"$package" "$installed" "$candidate" ;;
esac
[ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100
done
}