summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-09-11 01:28:25 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-09-11 15:23:29 -0400
commit589186164cfbb1e033b9dfad33c9bf82b9404b1c (patch)
tree3919316871a4b17c35d2b74971c86b52f1ae73b0
parent76b27c5c5a705770fbab763199dd32efc279170a (diff)
test: change how we do sudo (to make sure we stay in the test environment)
-rw-r--r--test/lib-conf-test.sh8
-rw-r--r--test/librechroot-test.sh12
-rw-r--r--test/libremakepkg-test.sh2
-rwxr-xr-xtest/testenv17
4 files changed, 29 insertions, 10 deletions
diff --git a/test/lib-conf-test.sh b/test/lib-conf-test.sh
index 86c11c6..0d028b8 100644
--- a/test/lib-conf-test.sh
+++ b/test/lib-conf-test.sh
@@ -23,11 +23,13 @@ it_sets_makepkg_vars_in_custom_file() {
it_figures_out_HOME_when_root() {
require sudo || return 0
+ # 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=$(sudo -EH bash ./test.sh)
- [[ $LIBREHOME == $HOME ]]
+ LIBREHOME=$(testsudo bash ./test.sh)
+ [[ $LIBREHOME != /root ]]
}
it_respects_custom_HOME() {
diff --git a/test/librechroot-test.sh b/test/librechroot-test.sh
index 06abd23..8545380 100644
--- a/test/librechroot-test.sh
+++ b/test/librechroot-test.sh
@@ -20,15 +20,15 @@ after() {
it_creates_repo_for_new_chroots() {
require network sudo || return 0
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- sudo -EH librechroot run test -r /repo/repo.db
+ testsudo librechroot 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
- sudo -EH librechroot make
- sudo -EH librechroot clean-repo
- sudo -EH librechroot run test -r /repo/repo.db
+ testsudo librechroot make
+ testsudo librechroot clean-repo
+ testsudo librechroot run test -r /repo/repo.db
# TODO: inspect /repo/* more
}
@@ -59,7 +59,7 @@ it_displays_help_and_fails_with_0_args() {
# requires sudo so we know it's not failing because it needs root
it_fails_for_unknown_commands() {
require sudo || return 0
- sudo -EH librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
[[ -z "$(cat $tmpdir/stdout)" ]]
@@ -69,7 +69,7 @@ it_fails_for_unknown_commands() {
# requires sudo so we know it's not failing because it needs root
it_fails_for_unknown_flags() {
require sudo || return 0
- sudo -EH librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+ testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
[[ -z "$(cat $tmpdir/stdout)" ]]
diff --git a/test/libremakepkg-test.sh b/test/libremakepkg-test.sh
index 8a4fa63..95080af 100644
--- a/test/libremakepkg-test.sh
+++ b/test/libremakepkg-test.sh
@@ -23,7 +23,7 @@ it_builds_a_trivial_package() {
cd "$tmpdir"
libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty
- sudo -EH libremakepkg
+ testsudo libremakepkg
[[ -f $(echo libretools-hello-1.0-1-any.pkg.tar.?z) ]]
}
diff --git a/test/testenv b/test/testenv
index 12a5901..e6f49fb 100755
--- a/test/testenv
+++ b/test/testenv
@@ -39,5 +39,22 @@ export HOME=$TMPDIR/home
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
+# Hack to respect our variables in sudo
+_sudo() {
+ local vars=(TMPDIR PATH LIBRETOOLS_LIBDIR XDG_CACHE_HOME XDG_CONFIG_HOME)
+ local args=()
+ local var
+ for var in "${vars[@]}"; do
+ args+=("$var=${!var}")
+ done
+ sudo env "${args[@]}" "$@"
+}
+printf '%s\n' \
+ '#!/bin/bash' \
+ "$(declare -f _sudo)" \
+ '_sudo "$@"' \
+ > "$destdir/usr/bin/testsudo"
+chmod 755 "$destdir/usr/bin/testsudo"
+
# Run the tests
eval "$@"