summaryrefslogtreecommitdiff
path: root/test/cases/lib-conf.bats
blob: 0925640d86103f7253572a617d32ae4c04c67b15 (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
load ../lib/common

@test "lib/conf.sh sets makepkg vars in custom file" {
	unset PKGDEST
	touch "$tmpdir/makepkg.conf"
	bash -c "$(printf '. $(librelib conf.sh); MAKEPKG_CONF=%q set_var makepkg PKGDEST /pkgdest' "$tmpdir/makepkg.conf")"
	.  "$tmpdir/makepkg.conf"
	[[ $PKGDEST == /pkgdest ]]
}

@test "lib/conf.sh figures out HOME when root" {
	require sudo || skip
	# This one is tricky, because it does the job too well, it will find
	# the actual HOME, instead of the test environment HOME.  Therefore, we
	# will just check that [[ $HOME != /root ]]
	cd "$tmpdir"
	echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh
	LIBREHOME=$(testsudo bash ./test.sh)
	[[ $LIBREHOME != /root ]]
}

@test "lib/conf.sh nests LIBREUSER" {
	require sudo || skip
	[[ $USER != root ]]
	cd "$tmpdir"
	echo '. $(librelib conf.sh); echo "$LIBREUSER"' > test.sh

	LIBREUSER=$(testsudo bash ./test.sh)
	[[ $LIBREUSER == "$USER" ]]

	LIBREUSER=$(testsudo testsudo -u "$USER" bash ./test.sh)
	[[ $LIBREUSER == "$USER" ]]
}

@test "lib/conf.sh respects custom HOME" {
	cd "$tmpdir"
	echo '. $(librelib conf.sh); echo "$LIBREHOME"' > test.sh

	export HOME=/foo
	LIBREHOME=$(bash ./test.sh)

	[[ $LIBREHOME == /foo ]]
}