diff --git a/xCAT-test/bats/go_xcat_apt_install.bats b/xCAT-test/bats/go_xcat_apt_install.bats index 9b4ff8e001..322c4688a9 100644 --- a/xCAT-test/bats/go_xcat_apt_install.bats +++ b/xCAT-test/bats/go_xcat_apt_install.bats @@ -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 "$@" ) diff --git a/xCAT-test/bats/go_xcat_package_listing.bats b/xCAT-test/bats/go_xcat_package_listing.bats new file mode 100644 index 0000000000..7d504e2c34 --- /dev/null +++ b/xCAT-test/bats/go_xcat_package_listing.bats @@ -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; } +} diff --git a/xCAT-test/bats/helpers/go_xcat_apt.bash b/xCAT-test/bats/helpers/go_xcat_apt.bash new file mode 100644 index 0000000000..550aa06147 --- /dev/null +++ b/xCAT-test/bats/helpers/go_xcat_apt.bash @@ -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 +}