lifecycle.bats 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. DIRS="usr/sbin/netdata
  17. etc/netdata
  18. usr/share/netdata
  19. usr/libexec/netdata
  20. var/cache/netdata
  21. var/lib/netdata
  22. var/log/netdata"
  23. setup() {
  24. # If we are not in netdata git repo, at the top level directory, fail
  25. TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
  26. CWD=$(git rev-parse --show-cdup || echo "")
  27. if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
  28. echo "Run as ./tests/lifecycle/$(basename "$0") from top level directory of git repository"
  29. exit 1
  30. fi
  31. }
  32. @test "install netdata" {
  33. ./netdata-installer.sh --dont-wait --dont-start-it --auto-update --install "${INSTALLATION}"
  34. # Validate particular files
  35. for file in $FILES; do
  36. [ ! -f "$BATS_TMPDIR/$file" ]
  37. done
  38. # Validate particular directories
  39. for a_dir in $DIRS; do
  40. [ ! -d "$BATS_TMPDIR/$a_dir" ]
  41. done
  42. }
  43. @test "update netdata" {
  44. export ENVIRONMENT_FILE="${ENV}"
  45. ${INSTALLATION}/netdata/usr/libexec/netdata/netdata-updater.sh --not-running-from-cron
  46. ! grep "new_installation" "${ENV}"
  47. }
  48. @test "uninstall netdata" {
  49. ./packaging/installer/netdata-uninstaller.sh --yes --force --env "${ENV}"
  50. [ ! -f "${INSTALLATION}/netdata/usr/sbin/netdata" ]
  51. [ ! -f "/etc/cron.daily/netdata-updater" ]
  52. }