common 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. if [[ -v testname ]]; then
  19. return
  20. fi
  21. declare -r testname=`basename $0`
  22. section_start() {
  23. local name header
  24. name="${1:?}"
  25. header="${2:-} (${testname})"
  26. echo -e "section_start:$(date +%s):${testname}_${name}\r\e[0K\e[36;1m${header}\e[0;m"
  27. }
  28. section_end() {
  29. local name
  30. name="${1:?}"
  31. echo -e "section_end:$(date +%s):${testname}_${name}\r\e[0K"
  32. }
  33. _escape_newline() {
  34. echo "$1" | perl -pe 's/\n/\\n/g'
  35. }
  36. assert-equal() {
  37. if [[ "${2}" != "${3}" ]]; then
  38. local actual=$(_escape_newline "$2") expected=$(_escape_newline "$3")
  39. echo "E: ${1} returned '${actual}' (expected: '${expected}')" >&2
  40. exit 1
  41. fi
  42. }
  43. fixture-package-dir() {
  44. packages=${DAK_ROOT:?}/tests/fixtures/packages
  45. echo "${packages}"
  46. }
  47. import-fixture-signing-key() {
  48. packages=$(fixture-package-dir)
  49. ln -sf ${packages:?}/gpg/pubring.gpg ${DAKBASE:?}/keyrings/upload-keyring.gpg
  50. dak import-keyring -U "%s" ${DAKBASE}/keyrings/upload-keyring.gpg
  51. }
  52. check_all_suites() {
  53. # list all suites and compare the control-suite output to the reference
  54. # output from the repo
  55. checkname=$1
  56. if [ -z "$checkname" ]
  57. then
  58. echo "E: $testname: check_all_suites called without checkname"
  59. exit 1
  60. fi
  61. csdir="${DAKBASE}/testoutput/$testname/$checkname"
  62. refdir="${DAK_ROOT}/integration-tests/test-output/$testname/$checkname"
  63. if [ ! -d "$refdir" ]
  64. then
  65. echo "E: $testname: dir $refdir missing"
  66. exit 1
  67. fi
  68. suitesdir="$csdir/suites"
  69. mkdir -p "$csdir/archives"
  70. dak admin archive list | sort | while read archive pathinfo rest
  71. do
  72. pathinfo=${pathinfo#*=}
  73. (
  74. cd $pathinfo 2> /dev/null && (
  75. find . | \
  76. # replace the hashes with XXXX
  77. perl -pe 's;(by-hash/[^/]*/)([0-9a-f]*)$;($1.('X' x length($2)));e' |\
  78. # replace times with XXXX
  79. perl -pe 's;(\d\d\d\d-\d\d-\d\d-\d\d\d\d.\d\d);XXXX-XX-XX-XXXX.XX;'
  80. ) || true
  81. ) | LANG=C sort > "$csdir/archives/$archive"
  82. done
  83. mkdir -p "$suitesdir"
  84. dak admin s list | sort | while read suite
  85. do
  86. printf "\n\n$suite\n"
  87. dak control-suite -l $suite | LANG=C sort | tee "$suitesdir/$suite"
  88. done
  89. if ! diff -Nur "$refdir" "$csdir"
  90. then
  91. echo "E: $testname $checkname: output different"
  92. exit 1
  93. fi
  94. }
  95. check_output() {
  96. # run a command and compare the output to the reference output from the
  97. # repo
  98. checkname=$1
  99. command="$2"
  100. if [ -z "$command" ]
  101. then
  102. echo "E: $testname: check_output called without command"
  103. exit 1
  104. fi
  105. ofile="${DAKBASE}/testoutput/$testname/commands/$checkname"
  106. reffile="${DAK_ROOT}/integration-tests/test-output/$testname/commands/$checkname"
  107. if [ ! -f "$reffile" ]
  108. then
  109. echo "E: $testname: file $reffile missing"
  110. exit 1
  111. fi
  112. mkdir -p `dirname $ofile`
  113. $command > $ofile
  114. if ! diff -Nur "$reffile" "$ofile"
  115. then
  116. echo "E: $testname $checkname: output different"
  117. exit 1
  118. fi
  119. }
  120. save_ci_artifact() {
  121. filename="$1"
  122. if [ ! -d "${DAK_CI_OUTPUT_DIR:-}" ]
  123. then
  124. echo "DAK_CI_OUTPUT_DIR not set, not saving artifact $filename"
  125. return
  126. fi
  127. destdir="${DAK_CI_OUTPUT_DIR}/$testname/"
  128. mkdir -p "$destdir"
  129. cp "$filename" "$destdir"
  130. }