test-failing-maintainer-scripts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'native'
  7. configdpkgnoopchroot
  8. # create a bunch of failures
  9. createfailure() {
  10. setupsimplenativepackage "failure-$1" 'native' '1.0' 'unstable' 'Depends: dependee'
  11. BUILDDIR="incoming/failure-$1-1.0"
  12. echo '#!/bin/sh
  13. exit 29' > "${BUILDDIR}/debian/$1"
  14. buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
  15. rm -rf "$BUILDDIR"
  16. }
  17. buildsimplenativepackage 'dependee' 'native' '1.0' 'unstable'
  18. createfailure 'preinst'
  19. createfailure 'postinst'
  20. createfailure 'prerm'
  21. createfailure 'postrm'
  22. setupaptarchive
  23. # setup some pre- and post- invokes to check the output isn't garbled later
  24. APTHOOK="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apthook"
  25. echo '#!/bin/sh
  26. echo "$1: START"
  27. echo "$1: MaiN"
  28. echo "$1: ENd"' > "$APTHOOK"
  29. chmod +x "$APTHOOK"
  30. echo "DPKG::Pre-Invoke:: \"${APTHOOK} PRE\";
  31. DPKG::Post-Invoke:: \"${APTHOOK} POST\";" > rootdir/etc/apt/apt.conf.d/99apthooks
  32. testmyfailure() {
  33. local PROGRESS='rootdir/tmp/progress.log'
  34. exec 3> "$PROGRESS"
  35. testfailure "$@" -o APT::Status-Fd=3
  36. msgtest 'Test for failure message of maintainerscript in' 'console log'
  37. local TEST='rootdir/tmp/testfailure.output'
  38. if grep -q 'exit status 29' "$TEST"; then
  39. msgpass
  40. else
  41. cat "$TEST"
  42. msgfail
  43. fi
  44. msgtest 'Test for proper execution of invoke scripts in' 'console log'
  45. if grep -q '^PRE: START$' "$TEST" &&
  46. grep -q '^PRE: MaiN$' "$TEST" &&
  47. grep -q '^PRE: ENd$' "$TEST" &&
  48. grep -q '^POST: START$' "$TEST" &&
  49. grep -q '^POST: MaiN$' "$TEST" &&
  50. grep -q '^POST: ENd$' "$TEST"; then
  51. msgpass
  52. else
  53. cat "$TEST"
  54. msgfail
  55. fi
  56. msgtest 'Test for failure message of maintainerscript in' 'progress log'
  57. if grep -q '^pmerror:.\+exit status 29$' "$PROGRESS"; then
  58. msgpass
  59. else
  60. cat "$PROGRESS"
  61. msgfail
  62. fi
  63. testmarkedauto 'dependee'
  64. }
  65. cp -a rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status.backup
  66. testmyfailure aptget install failure-preinst -y
  67. cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
  68. testmyfailure aptget install failure-postinst -y
  69. cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
  70. testsuccess aptget install failure-prerm -y
  71. testdpkginstalled failure-prerm
  72. testmyfailure aptget purge failure-prerm -y
  73. cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
  74. testsuccess aptget install failure-postrm -y
  75. testdpkginstalled failure-postrm
  76. testmyfailure aptget purge failure-postrm -y
  77. # FIXME: test with output going to a PTY as it usually does
  78. if false; then
  79. cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
  80. apt install dependee -y || true
  81. apt install failure-postinst -y || true
  82. fi