lifecycle.bats 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bats
  2. #
  3. # Netdata installation lifecycle testing script.
  4. # This is to validate the install, update and uninstall of netdata
  5. #
  6. # Copyright: SPDX-License-Identifier: GPL-3.0-or-later
  7. #
  8. # Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud)
  9. #
  10. INSTALLATION="$BATS_TMPDIR/installation"
  11. ENV="${INSTALLATION}/netdata/etc/netdata/.environment"
  12. # list of files which need to be checked. Path cannot start from '/'
  13. FILES="usr/libexec/netdata/plugins.d/go.d.plugin
  14. usr/libexec/netdata/plugins.d/charts.d.plugin
  15. usr/libexec/netdata/plugins.d/python.d.plugin
  16. usr/libexec/netdata/plugins.d/node.d.plugin"
  17. DIRS="usr/sbin/netdata
  18. etc/netdata
  19. usr/share/netdata
  20. usr/libexec/netdata
  21. var/cache/netdata
  22. var/lib/netdata
  23. var/log/netdata"
  24. setup() {
  25. # If we are not in netdata git repo, at the top level directory, fail
  26. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  27. CWD=$(git rev-parse --show-cdup || echo "")
  28. if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  29. echo "Run as ./tests/lifecycle/$(basename "$0") from top level directory of git repository"
  30. exit 1
  31. fi
  32. }
  33. @test "install netdata" {
  34. ./netdata-installer.sh --dont-wait --dont-start-it --auto-update --install "${INSTALLATION}"
  35. # Validate particular files
  36. for file in $FILES; do
  37. [ ! -f "$BATS_TMPDIR/$file" ]
  38. done
  39. # Validate particular directories
  40. for a_dir in $DIRS; do
  41. [ ! -d "$BATS_TMPDIR/$a_dir" ]
  42. done
  43. }
  44. @test "update netdata" {
  45. export ENVIRONMENT_FILE="${ENV}"
  46. ${INSTALLATION}/netdata/usr/libexec/netdata/netdata-updater.sh --not-running-from-cron
  47. ! grep "new_installation" "${ENV}"
  48. }
  49. @test "uninstall netdata" {
  50. ./packaging/installer/netdata-uninstaller.sh --yes --force --env "${ENV}"
  51. [ ! -f "${INSTALLATION}/netdata/usr/sbin/netdata" ]
  52. [ ! -f "/etc/cron.daily/netdata-updater" ]
  53. }