123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #!/bin/bash
- #shellcheck disable=SC1091,SC2034
-
- Installed=
- Custom=
- Select=
-
- shellfu import jat_dump
- shellfu import preupg
- shellfu import preupg_fupath
- shellfu import xcase
-
- xcase__enum() {
- #
- # Enumerate use case ids
- #
- xcase__permute Installed 0 1 2 \
- | xcase__per Custom 0 1 2 \
- | xcase__per Select none s_ok c_ok s_bad c_bad both
- }
-
- mk_cupath() {
- #
- # Build custom upath
- #
- local name
- for name in "$@"; do
- preupg_fupath "$name" @pass @informational @fixed
- done
- }
-
- xcase__setup() {
- #
- # Setup and collect data
- #
- local t_selargs # selection arguments
-
- case $Installed in
- 0) : ;;
- 1) mk_cupath INS1; cp -r INS1 /usr/share/preupgrade ;;
- 2) mk_cupath INS{1,2}; cp -r INS{1,2} /usr/share/preupgrade ;;
- *) xcase__id_error Installed ;;
- esac
-
- case $Custom in
- 0) : ;;
- 1) mk_cupath CUS1 ;;
- 2) mk_cupath CUS{1,2} ;;
- *) xcase__id_error Custom ;;
- esac
-
- case $Select in
- none) t_selargs=() ;;
- s_ok) t_selargs=(-s INS1) ;;
- s_bad) t_selargs=(-s BLAH) ;;
- c_ok) t_selargs=(-c CUS1/all-xccdf.xml) ;;
- c_bad) t_selargs=(-c CUS3/all-xccdf.xml) ;;
- both) t_selargs=(-s INS1 -c CUS1/all-xccdf.xml) ;;
- *) xcase__id_error Select ;;
- esac
-
- jat__cmd -S 0,1,20,22 -o preupg.out -e preupg.err \
- preupg --list-rules "${t_selargs[@]}"
- echo $? >r_es
- }
-
- xcase__test() {
- #
- # Verify result = oracle
- #
- local o_err=false # oracle: error output?
- local o_es # oracle: preupg exit status
- local o_lines # oracle: normal output line count
- local r_err=false # result: error output?
- local r_es # result: preupg exit status
- local r_lines # result: normal output line count
- grep '^xccdf' preupg.out >preupg.out.filtered; # FIXME: remove and use normal .out
- r_lines=$(<preupg.out.filtered wc -l) # after https://github.com/upgrades-migrations/preupgrade-assistant/issues/333
- test -s preupg.err && r_err=true
- r_es=$(<r_es)
-
- case $Installed:$Custom:$Select in
-
- *:both) o_lines=0; o_es=22; o_err=true ;;
-
- 0:0:*) o_lines=0; o_es=20; o_err=true ;;
- 1:*:none) o_lines=3; o_es=0; o_err=false ;;
- *:none) o_lines=0; o_es=20; o_err=true ;;
-
- 0:*:s_ok) o_lines=0; o_es=20; o_err=true ;;
- *:s_ok) o_lines=3; o_es=0; o_err=false ;;
- *:s_bad) o_lines=0; o_es=20; o_err=true ;;
-
- *:0:c_ok) o_lines=0; o_es=20; o_err=true ;;
- *:c_ok) o_lines=3; o_es=0; o_err=false ;;
- *:c_bad) o_lines=0; o_es=20; o_err=true ;;
-
- *) xcase__id_error Installed Custom Select ;;
- esac
-
- jat__cmp -h "number of listed lines is correct" \
- "$r_lines" eq "$o_lines"
- jat__cmp -h "exit status from preupg is correct" \
- "$r_es" eq "$o_es"
- # jat__cmp -h "error output does (not) exist as expected" \
- # "$r_err" eq "$o_err"
- # FIXME: enable stderr assert after https://github.com/upgrades-migrations/preupgrade-assistant/issues/333
- }
-
- xcase__diag() {
- dump__file preupg.out preupg.out.filtered preupg.err
- }
-
- xcase__cleanup() {
- jat__cmd rm -rf /usr/share/preupgrade/INS*
- preupg__rmresult
- }
-
- xcase__run -v
- preupg__Cleanup
|