summaryrefslogtreecommitdiffstats
path: root/tests/lifecycle.bats
blob: bf626fe13d3331ec8d41d69928a38f87326ff120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bats
#
# Netdata installation lifecycle testing script.
# This is to validate the install, update and uninstall of netdata
#
# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
#
# Author  : Pavlos Emm. Katsoulakis <paul@netdata.cloud)
#

INSTALLATION="$BATS_TMPDIR/installation"
ENV="${INSTALLATION}/netdata/etc/netdata/.environment"
# list of files which need to be checked. Path cannot start from '/'
FILES="usr/libexec/netdata/plugins.d/go.d.plugin
       usr/libexec/netdata/plugins.d/charts.d.plugin
       usr/libexec/netdata/plugins.d/python.d.plugin"

DIRS="usr/sbin/netdata
      etc/netdata
      usr/share/netdata
      usr/libexec/netdata
      var/cache/netdata
      var/lib/netdata
      var/log/netdata"

setup() {
	# If we are not in netdata git repo, at the top level directory, fail
	TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
	CWD=$(git rev-parse --show-cdup || echo "")
	if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" == "netdata" ]; then
		echo "Run as ./tests/lifecycle/$(basename "$0") from top level directory of git repository"
		exit 1
	fi
}

@test "install netdata" {
	./netdata-installer.sh  --dont-wait --dont-start-it --auto-update --install "${INSTALLATION}"

	# Validate particular files
	for file in $FILES; do
		[ ! -f "$BATS_TMPDIR/$file" ]
	done

	# Validate particular directories
	for a_dir in $DIRS; do
		[ ! -d "$BATS_TMPDIR/$a_dir" ]
	done
}

@test "update netdata" {
	export ENVIRONMENT_FILE="${ENV}"
	${INSTALLATION}/netdata/usr/libexec/netdata/netdata-updater.sh --not-running-from-cron
	! grep "new_installation" "${ENV}"
}

@test "uninstall netdata" {
	./packaging/installer/netdata-uninstaller.sh --yes --force --env "${ENV}"
	[ ! -f "${INSTALLATION}/netdata/usr/sbin/netdata" ]
	[ ! -f "/etc/cron.daily/netdata-updater" ]
}