test-apt-extracttemplates 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. # apt-extracttemplates needs this
  8. insertinstalledpackage 'pkg-with-template' 'amd64' '1.0'
  9. # build a simple package that contains a config and a template
  10. mkdir -p DEBIAN
  11. CONFIG_STR="#!/bin/sh
  12. random shell stuff
  13. "
  14. echo "$CONFIG_STR" > DEBIAN/config
  15. testrun() {
  16. local TEMPLATE_STR='Template: foo/bar
  17. Type: string
  18. Description: Some bar var
  19. '
  20. echo "$TEMPLATE_STR" > DEBIAN/templates
  21. buildsimplenativepackage "$1" 'amd64' '0.8.15' 'stable' "$2" 'pkg with template' '' '' './DEBIAN'
  22. cp dpkg.status rootdir/var/lib/dpkg/status
  23. insertinstalledpackage 'debconf' 'amd64' '3'
  24. # ensure we get the right stuff out of the file
  25. rm -rf extracttemplates-out rootdir/var/cache/apt
  26. mkdir extracttemplates-out
  27. testsuccess aptextracttemplates -t ./extracttemplates-out incoming/${1}*.deb
  28. OUT='rootdir/tmp/testsuccess.output'
  29. testequal "$1" cut -f1 -d' ' $OUT
  30. if [ -n "$2" ]; then
  31. testequal '' cut -s -f2 -d' ' $OUT
  32. else
  33. testequal '1.0' cut -f2 -d' ' $OUT
  34. fi
  35. TEMPLATE=$(cut -f3 -d' ' $OUT)
  36. testfileequal "$TEMPLATE" "$TEMPLATE_STR"
  37. CONFIG=$(cut -f4 -d' ' $OUT)
  38. testfileequal "$CONFIG" "$CONFIG_STR"
  39. # ensure that the format of the output string has the right number of dots
  40. for s in "$CONFIG" "$TEMPLATE"; do
  41. NR_DOTS=$(basename "$s" | tr -c -d '.')
  42. testequal '..' echo $NR_DOTS
  43. done
  44. if [ -n "$2" ]; then
  45. rm -rf extracttemplates-out rootdir/var/cache/apt
  46. mkdir extracttemplates-out
  47. cp dpkg.status rootdir/var/lib/dpkg/status
  48. insertinstalledpackage 'debconf' 'amd64' '1'
  49. testempty aptextracttemplates -t ./extracttemplates-out incoming/${1}*.deb
  50. fi
  51. }
  52. cp rootdir/var/lib/dpkg/status dpkg.status
  53. testrun 'pkg-with-template' ''
  54. testrun 'pkg-with-template-depends' 'Depends: debconf (>= 2)'
  55. testrun 'pkg-with-template-predepends' 'Pre-Depends: debconf (>= 2)'
  56. # test with no debconf installed
  57. cp dpkg.status rootdir/var/lib/dpkg/status
  58. testfailure aptextracttemplates -t ./extracttemplates-out incoming/pkg-with-template-depends*.deb
  59. testfileequal 'rootdir/tmp/testfailure.output' 'E: Cannot get debconf version. Is debconf installed?'