Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

tests-e2e.sh 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "make build"
  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. assertFailure "kosmorro --date=1789-05-05"
  67. assertFailure "kosmorro --date=3000-01-01"
  68. assertSuccess "kosmorro --date='+3y 5m3d'"
  69. assertSuccess "kosmorro --date='-1y3d'"
  70. assertFailure "kosmorro --date='+3d4m"
  71. assertFailure "kosmorro -date='3y'"
  72. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624"
  73. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27"
  74. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=1"
  75. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=-1"
  76. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=json"
  77. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf"
  78. # Environment variables
  79. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=1 kosmorro -d 2020-01-27"
  80. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=-1 kosmorro -d 2020-01-27"
  81. # Missing dependencies, should fail
  82. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  83. assertSuccess "sudo apt-get install -y texlive" "CI"
  84. assertSuccess "$PIP_BIN install latex" "CI"
  85. # Dependencies installed, should not fail
  86. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  87. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf --no-graph"
  88. # man page
  89. assertSuccess "man --pager=cat kosmorro"
  90. if [ "$failures" != "" ]; then
  91. echo -e "\n$failures"
  92. exit 2
  93. fi
  94. echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="