summaryrefslogtreecommitdiff
path: root/test/librechroot-test.sh
blob: c3026dae519bdf8131ae2f95355372b1b5d8f05f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env roundup

describe librechroot

. ./test-common.sh

_setup_chrootdir

before() {
	_before librechroot

	mkdir -p "$XDG_CONFIG_HOME"/libretools

	echo "CHROOTDIR='${chrootdir}'" > "$XDG_CONFIG_HOME"/libretools/chroot.conf
	echo "CHROOT='default'" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
	echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
}

after() (
	_after_sudo
)

it_creates_repo_for_new_chroots() {
	require network sudo || return 0
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
	testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db
}

it_cleans_the_local_repo_correctly() {
	require network sudo || return 0
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
	testsudo librechroot -l "$roundup_test_name" make
	testsudo librechroot -l "$roundup_test_name" clean-repo
	testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db
	# TODO: inspect /repo/* more
}

it_respects_exit_status_if_out_isnt_a_tty() (
	require network sudo || return 0
	set -o pipefail
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
	r=0
	{ testsudo librechroot -l "$roundup_test_name" run bash -c 'exit 3' | cat; } || r=$?

	# Work around http://lists.freedesktop.org/archives/systemd-devel/2014-June/020685.html
	# Hopefully the fix gets merged for 215
	systemd_ver=$(systemd-nspawn --version|sed -n 's|^systemd ||p')
	if [[ $systemd_ver =~ 213|214 ]]; then
		[[ $r == 1 ]]
	else
		[[ $r == 3 ]]
	fi
)

it_creates_ca_certificates() {
	require network sudo || return 0
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
	testsudo librechroot -l "$roundup_test_name" run test -r /etc/ssl/certs/ca-certificates.crt
}

it_disables_networking_when_requested() {
	require network sudo || return 0
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty

	    testsudo librechroot -l "$roundup_test_name"    run curl https://repo.parabolagnulinux.org/ >/dev/null
	not testsudo librechroot -l "$roundup_test_name" -N run curl https://repo.parabolagnulinux.org/ >/dev/null
}

it_handles_CHROOTEXTRAPKG_correctly() {
	requuire network sudo || return 0
	libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty

	not testsudo librechroot -l "$roundup_test_name" run lsof
	echo "CHROOTEXTRAPKG=(lsof)" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
	testsudo librechroot -l "$roundup_test_name" install-name lsof
	testsudo librechroot -l "$roundup_test_name" clean-pkgs
	testsudo librechroot -l "$roundup_test_name" run lsof
	echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf
	testsudo librechroot -l "$roundup_test_name" clean-pkgs
	not testsudo librechroot -l "$roundup_test_name" run lsof
}

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

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

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

	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}

it_displays_help_and_fails_with_0_args() {
	LC_ALL=C librechroot -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	[[ "$(sed -n 2p $tmpdir/stderr)" =~ Usage:.* ]]
}

# requires sudo so we know it's not failing because it needs root
it_fails_for_unknown_commands() {
	require sudo || return 0
	testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}

# requires sudo so we know it's not failing because it needs root
it_fails_for_unknown_flags() {
	require sudo || return 0
	testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}