Skip to content

Commit

Permalink
Added missing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesage committed Aug 8, 2024
1 parent ff37331 commit 08e517f
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_login_env_vars.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/env bats

setup() {
load setup_common
load setup_container_daemon
}

teardown() {
load teardown_container_daemon
load teardown_common
}

@test "Checking that internal environment variables are exposed when logging in..." {
exec_container_daemon sh -c "[ -f /root/.profile ] && . /root/.profile || . /root/.docker_rc; env | grep -w XDG_DATA_HOME"
}

# vim:ft=sh:ts=4:sw=4:et:sts=4
90 changes: 90 additions & 0 deletions tests/test_pkgs_mirror.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/env bats

setup() {
load setup_common

echo "#!/bin/sh
exit 0" > "$TESTS_WORKDIR"/startapp.sh
chmod a+rx "$TESTS_WORKDIR"/startapp.sh
}

teardown() {
load teardown_common
}

@test "Checking that packages mirror can be set successfully..." {
docker_run --rm -e "PACKAGES_MIRROR=https://example.com" -v "$TESTS_WORKDIR"/startapp.sh:/startapp.sh $DOCKER_IMAGE
echo "====================================================================="
echo " OUTPUT"
echo "====================================================================="
echo "$output"
echo "====================================================================="
echo " END OUTPUT"
echo "====================================================================="
echo "STATUS: $status"
[ "$status" -eq 0 ]

regex=".* setting packages mirror to 'https://example.com'"
for item in "${lines[@]}"; do
if [[ "$item" =~ $regex ]]; then
break;
fi
done
[[ "$item" =~ $regex ]]
}

@test "Checking that package can be installed successfully when a mirror is set..." {
docker_run --rm $DOCKER_IMAGE uname -m
[ "$status" -eq 0 ]
ARCH="${lines[0]}"

docker_run --rm $DOCKER_IMAGE cat /etc/os-release
[ "$status" -eq 0 ]

regex="^ID=.*"
for item in "${lines[@]}"; do
if [[ "$item" =~ $regex ]]; then
OS="${item#*=}"
break;
fi
done

case "$OS" in
alpine)
MIRROR="http://uk.alpinelinux.org/alpine/"
;;
debian)
MIRROR="http://ftp.us.debian.org/debian/"
;;
ubuntu)
case "$ARCH" in
i386|i686|x86_64)
MIRROR="http://mirror.math.princeton.edu/pub/ubuntu/"
;;
*)
MIRROR="http://in.mirror.coganng.com/ubuntu-ports/"
;;
esac
;;
arch)
MIRROR="http://arch.mirror.square-r00t.net"
;;
*)
echo "ERROR: Unknown OS '$OS'."
exit 1
;;
esac

docker_run --rm -e "PACKAGES_MIRROR=$MIRROR" -e "INSTALL_PACKAGES=patchelf" -v "$TESTS_WORKDIR"/startapp.sh:/startapp.sh $DOCKER_IMAGE
echo "====================================================================="
echo " OUTPUT"
echo "====================================================================="
echo "$output"
echo "====================================================================="
echo " END OUTPUT"
echo "====================================================================="
echo "STATUS: $status"
[ "$status" -eq 0 ]
}

# vim:ft=sh:ts=4:sw=4:et:sts=4

0 comments on commit 08e517f

Please sign in to comment.