From 4d32bf4ad85967cc004c202e4e7442ccfdfddfac Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Wed, 26 Nov 2014 23:47:06 +0100 Subject: [PATCH] Close issue #20 --- tests/test_core.sh | 25 ++++++++++------------ tests/utils.sh | 53 ++++++---------------------------------------- 2 files changed, 18 insertions(+), 60 deletions(-) diff --git a/tests/test_core.sh b/tests/test_core.sh index 5c85925..2aacca6 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -1,18 +1,15 @@ #!/bin/bash -# To test this module you need to run it inside a Archlinux system. Also, the following packages needs to be installed: -# bash -# pacman -# arch-install-scripts -# proot -# coreutils -# grep -# sudo -# gawk source "$(dirname $0)/utils.sh" CURRPWD=$PWD +JUJU_MAIN_HOME=/tmp/jujutesthome +[ -e $JUJU_MAIN_HOME ] || JUJU_HOME=$JUJU_MAIN_HOME bash --rcfile "$(dirname $0)/../lib/core.sh" -ic "setup_juju" JUJU_HOME="" +function install_mini_juju(){ + cp -rfa $JUJU_MAIN_HOME/* $JUJU_HOME +} + function set_up(){ cd $CURRPWD JUJU_HOME=$(TMPDIR=/tmp mktemp -d -t jujuhome.XXXXXXXXXX) @@ -99,14 +96,14 @@ function test_run_juju_as_root(){ function test_run_juju_as_user(){ install_mini_juju - local output=$(run_juju_as_user "" "mkdir -v /newdir2") - is_equal "$output" "/usr/bin/mkdir: created directory '/newdir2'" || return 1 + local output=$(run_juju_as_user "" "mkdir -v /newdir2" | awk -F: '{print $1}') + is_equal "$output" "/usr/bin/mkdir" || return 1 [ -e $JUJU_HOME/newdir2 ] is_equal $? 0 || return 1 SH="mkdir -v /newdir" - local output=$(run_juju_as_user "") - is_equal "$output" "/usr/bin/mkdir: created directory '/newdir'" || return 1 + local output=$(run_juju_as_user "" | awk -F: '{print $1}') + is_equal "$output" "/usr/bin/mkdir" || return 1 [ -e $JUJU_HOME/newdir ] is_equal $? 0 || return 1 } @@ -137,7 +134,7 @@ function test_run_juju_as_user_seccomp(){ function test_run_juju_as_fakeroot(){ install_mini_juju local output=$(run_juju_as_fakeroot "" "id" | awk '{print $1}') - is_equal "$output" "uid=0" || return 1 + is_equal "$output" "uid=0(root)" || return 1 } function test_delete_juju(){ diff --git a/tests/utils.sh b/tests/utils.sh index 9f6f263..094c055 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -1,50 +1,11 @@ -function install_executable(){ - for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq ) - do - cp -f --parents $i $JUJU_HOME - done - - # ARCH amd64 - if [ -f /lib64/ld-linux-x86-64.so.2 ]; then - cp -f --parents /lib64/ld-linux-x86-64.so.2 $JUJU_HOME - fi - - # ARCH i386 - if [ -f /lib/ld-linux.so.2 ]; then - cp -f --parents /lib/ld-linux.so.2 $JUJU_HOME - fi - - cp -f --parents $* $JUJU_HOME/ -} - -function install_package(){ - # Copy the directories - pacman -Ql $1 | grep "/$" | sed 's/.* //' | xargs -I {} mkdir -p $JUJU_HOME/{} - - # Copy the files - pacman -Ql $1 | grep -v "/$" | sed 's/.* //' | xargs -I {} cp -f --parents {} $JUJU_HOME - - # Copy the dynamic libraries of the executables - #export -f install_executable - #export JUJU_HOME - #pacman -Ql $1 | grep -v "/$" | sed 's/.* //' | grep "^/usr/bin/" | xargs -I {} bash -ic "install_executable {}" -} - -function install_mini_juju(){ - install_package filesystem 2> /dev/null - install_package arch-install-scripts - install_package bash - install_package proot - install_package coreutils - install_executable /usr/bin/bash - install_executable /usr/bin/ls - install_executable /usr/bin/mkdir - install_executable /usr/bin/proot -} - - function is_equal(){ - [ "$1" == "$2" ] || return 1 && return 0 + if [ "$1" == "$2" ] + then + return 0 + else + echo "$1!=$2" + return 1 + fi }