common 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # -*- mode: sh -*-
  2. #
  3. # © 2017 Ansgar Burchardt <ansgar@debian.org>
  4. # License: GPL-2+
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. declare -r testname=`basename $0`
  19. _escape_newline() {
  20. echo "$1" | perl -pe 's/\n/\\n/g'
  21. }
  22. assert-equal() {
  23. if [[ "${2}" != "${3}" ]]; then
  24. local actual=$(_escape_newline "$2") expected=$(_escape_newline "$3")
  25. echo "E: ${1} returned '${actual}' (expected: '${expected}')" >&2
  26. exit 1
  27. fi
  28. }
  29. fixture-package-dir() {
  30. packages=${DAK_ROOT:?}/tests/fixtures/packages
  31. echo "${packages}"
  32. }
  33. import-fixture-signing-key() {
  34. packages=$(fixture-package-dir)
  35. ln -sf ${packages:?}/gpg/pubring.gpg ${DAKBASE:?}/keyrings/upload-keyring.gpg
  36. dak import-keyring -U "%s" ${DAKBASE}/keyrings/upload-keyring.gpg
  37. }
  38. check_all_suites() {
  39. # list all suites and compare the control-suite output to the reference
  40. # output from the repo
  41. checkname=$1
  42. if [ -z "$checkname" ]
  43. then
  44. echo "E: $testname: check_all_suites called without checkname"
  45. exit 1
  46. fi
  47. csdir="${DAKBASE}/testoutput/$testname/$checkname"
  48. refdir="${DAK_ROOT}/integration-tests/test-output/$testname/$checkname"
  49. if [ ! -d "$refdir" ]
  50. then
  51. echo "E: $testname: dir $refdir missing"
  52. exit 1
  53. fi
  54. suitesdir="$csdir/suites"
  55. mkdir -p "$csdir/archives"
  56. dak admin archive list | sort | while read archive pathinfo rest
  57. do
  58. pathinfo=${pathinfo#*=}
  59. (
  60. cd $pathinfo 2> /dev/null && (
  61. find . | \
  62. # replace the hashes with XXXX
  63. perl -pe 's;(by-hash/[^/]*/)([0-9a-f]*)$;($1.('X' x length($2)));e' |\
  64. # replace times with XXXX
  65. perl -pe 's;(\d\d\d\d-\d\d-\d\d-\d\d\d\d.\d\d);XXXX-XX-XX-XXXX.XX;'
  66. ) || true
  67. ) | LANG=C sort > "$csdir/archives/$archive"
  68. done
  69. mkdir -p "$suitesdir"
  70. dak admin s list | sort | while read suite
  71. do
  72. printf "\n\n$suite\n"
  73. dak control-suite -l $suite | LANG=C sort | tee "$suitesdir/$suite"
  74. done
  75. if ! diff -Nur "$refdir" "$csdir"
  76. then
  77. echo "E: $testname $checkname: output different"
  78. exit 1
  79. fi
  80. }
  81. check_output() {
  82. # run a command and compare the output to the reference output from the
  83. # repo
  84. checkname=$1
  85. command="$2"
  86. if [ -z "$command" ]
  87. then
  88. echo "E: $testname: check_output called without command"
  89. exit 1
  90. fi
  91. ofile="${DAKBASE}/testoutput/$testname/commands/$checkname"
  92. reffile="${DAK_ROOT}/integration-tests/test-output/$testname/commands/$checkname"
  93. if [ ! -f "$reffile" ]
  94. then
  95. echo "E: $testname: file $reffile missing"
  96. exit 1
  97. fi
  98. mkdir -p `dirname $ofile`
  99. $command > $ofile
  100. if ! diff -Nur "$reffile" "$ofile"
  101. then
  102. echo "E: $testname $checkname: output different"
  103. exit 1
  104. fi
  105. }
  106. save_ci_artifact() {
  107. filename="$1"
  108. if [ ! -d "${DAK_CI_OUTPUT_DIR:-}" ]
  109. then
  110. echo "DAK_CI_OUTPUT_DIR not set, not saving artifact $filename"
  111. return
  112. fi
  113. destdir="${DAK_CI_OUTPUT_DIR}/$testname/"
  114. mkdir -p "$destdir"
  115. cp "$filename" "$destdir"
  116. }