integration-test.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. MINETEST_VERSION=5.2.0
  3. # prerequisites
  4. jq --version || exit 1
  5. curl --version || exit 1
  6. # ensure proper current directory
  7. CWD=$(dirname $0)
  8. cd ${CWD}
  9. # setup
  10. unset use_proxy
  11. unset http_proxy
  12. unset https_proxy
  13. unset HTTP_PROXY
  14. unset HTTPS_PROXY
  15. # run mail-server
  16. docker pull minetestmail/mail
  17. docker run --name mail --rm \
  18. -e WEBMAILKEY=myserverkey \
  19. -e WEBMAIL_DEBUG=true \
  20. --network host \
  21. minetestmail/mail &
  22. # wait for startup
  23. bash -c 'while !</dev/tcp/localhost/8080; do sleep 1; done;'
  24. # start minetest with mail mod
  25. docker pull registry.gitlab.com/minetest/minetest/server:${MINETEST_VERSION}
  26. docker run --rm --name minetest \
  27. -u root:root \
  28. -v $(pwd)/minetest.conf:/etc/minetest/minetest.conf:ro \
  29. -v $(pwd)/world.mt:/root/.minetest/worlds/world/world.mt \
  30. -v $(pwd)/auth.sqlite:/root/.minetest/worlds/world/auth.sqlite \
  31. -v $(pwd)/../:/root/.minetest/worlds/world/worldmods/mail \
  32. -v $(pwd)/test_mod:/root/.minetest/worlds/world/worldmods/mail_test \
  33. -e use_proxy=false \
  34. -e http_proxy= \
  35. -e HTTP_PROXY= \
  36. --network host \
  37. registry.gitlab.com/minetest/minetest/server:${MINETEST_VERSION} &
  38. # prepare cleanup
  39. function cleanup {
  40. # cleanup
  41. docker stop mail
  42. docker stop minetest
  43. }
  44. trap cleanup EXIT
  45. # wait for startup
  46. sleep 5
  47. # Execute calls against mail-server
  48. # login
  49. LOGIN_DATA='{"username":"test","password":"enter"}'
  50. RES=$(curl --data "${LOGIN_DATA}" -H "Content-Type: application/json" "http://127.0.0.1:8080/api/login")
  51. echo Login response: $RES
  52. SUCCESS=$(echo $RES | jq -r .success)
  53. TOKEN=$(echo $RES | jq -r .token)
  54. # login succeeded
  55. test "$SUCCESS" == "true" || exit 1
  56. # token extracted
  57. test -n "$TOKEN" || exit 1
  58. # fetch mails
  59. RES=$(curl -H "Authorization: ${TOKEN}" "http://127.0.0.1:8080/api/inbox")
  60. echo Mailbox: ${RES}
  61. # inbox count is 1
  62. test "$(echo $RES | jq '. | length')" == "1" || exit 1
  63. echo "Test complete!"