Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tests-e2e.sh 2.7 KiB

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. VERSION=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' kosmorrolib/version.py)
  3. PYTHON_BIN=$(command -v python)
  4. PIP_BIN=$(command -v pip)
  5. if python3 --version > /dev/null; then
  6. PYTHON_BIN=$(command -v python3)
  7. PIP_BIN=$(command -v pip3)
  8. fi
  9. failures=''
  10. function fail() {
  11. failures="$failures\n\n - $1\n\n$2"
  12. }
  13. function run() {
  14. eval "$1" &> /tmp/output.txt
  15. return $?
  16. }
  17. function canRun() {
  18. if [[ "$1" != "" && "$1" != "$ENVIRONMENT" ]]; then
  19. return 1
  20. fi
  21. return 0
  22. }
  23. # Asserts that command $1 has finished with sucess
  24. # $1: the command to run
  25. function assertSuccess() {
  26. if ! canRun "$2"; then
  27. echo -n 'I'
  28. return
  29. fi
  30. run "$1"
  31. returned=$?
  32. if [ $returned -ne 0 ]; then
  33. fail "Failed asserting that command '$1' finishes with success, returned status $returned." "$(cat /tmp/output.txt)"
  34. echo -n 'F'
  35. return
  36. fi
  37. echo -n '.'
  38. }
  39. # Asserts that command $1 has finished with sucess
  40. # $1: the command to run
  41. function assertFailure() {
  42. if ! canRun "$2"; then
  43. echo -n 'I'
  44. return
  45. fi
  46. run "$1"
  47. returned=$?
  48. if [ $returned -eq 0 ]; then
  49. fail "Failed asserting that command '$1' finishes with failure." "$(cat /tmp/output.txt)"
  50. echo -n 'F'
  51. return
  52. fi
  53. echo -n '.'
  54. }
  55. echo
  56. echo "==== RUNNING E2E TESTS ===="
  57. echo
  58. # Create the package and install it
  59. assertSuccess "$PYTHON_BIN setup.py sdist"
  60. assertSuccess "$PIP_BIN install dist/kosmorro-$VERSION.tar.gz" "CI"
  61. assertSuccess kosmorro
  62. assertSuccess "kosmorro -h"
  63. assertSuccess "kosmorro -d 2020-01-27"
  64. assertFailure "kosmorro -d yolo-yo-lo"
  65. assertFailure "kosmorro -d 2020-13-32"
  66. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624"
  67. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27"
  68. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=1"
  69. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=-1"
  70. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=json"
  71. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf"
  72. # Missing dependencies, should fail
  73. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  74. assertSuccess "sudo apt-get install -y texlive" "CI"
  75. assertSuccess "$PIP_BIN install latex" "CI"
  76. # Dependencies installed, should not fail
  77. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  78. # man page
  79. assertSuccess "man --pager=cat kosmorro"
  80. if [ "$failures" != "" ]; then
  81. echo -e "\n$failures"
  82. exit 2
  83. fi
  84. echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="