summaryrefslogtreecommitdiff
path: root/test/librechroot-test.sh
blob: 91349c2d93eacee584627174184e8805b9643f78 (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
#!/usr/bin/env roundup

describe librechroot

before() {
	tmpdir=$(mktemp -d --tmpdir test-librechroot.XXXXXXXXXXXX)
	mkdir -p "$XDG_CONFIG_HOME"/libretools
	echo "CHROOTDIR='$tmpdir'" > "$XDG_CONFIG_HOME"/libretools/chroot.conf
	stat=0
}

after() {
	rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME"
}

it_creates_repo_for_new_chroots() {
	sudo -EH librechroot run test -r /repo/repo.db
}

it_displays_help_as_normal_user() {
	rm -rf "$XDG_CONFIG_HOME"
	librechroot help >$tmpdir/stdout 2>$tmpdir/stderr

	[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
	[[ -z "$(cat $tmpdir/stderr)" ]]
}

it_otherwise_fails_as_normal_user() {
	librechroot run true >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
}

it_displays_help_and_fails_with_0_args() {
	librechroot >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ "$(sed 1q $tmpdir/stderr)" =~ Usage:.* ]]
}

it_fails_for_unknown_commands() {
	sudo -EH librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
}

it_fails_for_unknown_flags() {
	sudo -EH librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
}