Skip to content

Commit

Permalink
Fixed test scripts bugs.
Browse files Browse the repository at this point in the history
- Removed an exit inside a function in favor of return
- Constructed functions around tests that can be conditionally skipped ,
  so the return statement can be used to perform the skip.
  • Loading branch information
matejak committed Jun 1, 2018
1 parent 46c4965 commit 3842789
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tests/API/OVAL/unittests/test_object_component_type.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

stderr=`mktemp`

set -e
set -o pipefail

$OSCAP oval eval $srcdir/test_object_component_type.oval.xml 2> $stderr || ret=$?
$OSCAP oval eval $srcdir/test_object_component_type.oval.xml 2> $stderr
ret=$?
set -e
[ $ret -eq 1 ]

grep -q "Entity [']something_bogus['] has not been found in textfilecontent_item (id: [0-9]\+) specified by object [']oval:oscap:obj:10[']." $stderr
Expand Down
4 changes: 4 additions & 0 deletions tests/API/XCCDF/unittests/test_xccdf_transformation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -o pipefail

. ../../../test_common.sh

function perform_test {
# if xsltproc is not installed we will skip the test
require xsltproc || return 255

Expand All @@ -20,3 +21,6 @@ $OSCAP xccdf validate $result
assert_exists 1 '//*[namespace::*="http://checklists.nist.gov/xccdf/1.2"]'

rm $result
}

perform_test
2 changes: 1 addition & 1 deletion tests/probes/iflisteners/test_probes_iflisteners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function test_probes_iflisteners {

if [ `id -u` -ne 0 ]; then
echo you need to be root
exit 255
return 255
fi

local ret_val=0;
Expand Down
4 changes: 4 additions & 0 deletions tests/probes/maskattr/test_object_entity_mask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "file" || return 255

name=$(basename $0 .sh)
Expand All @@ -30,3 +31,6 @@ echo "Testing syschar values."
[ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "" ]

rm $result
}

perform_test
4 changes: 4 additions & 0 deletions tests/probes/maskattr/test_object_entity_mask_oval_5_9.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "file" || return 255

name=$(basename $0 .sh)
Expand All @@ -30,3 +31,6 @@ echo "Testing syschar values."
[ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "" ]

rm $result
}

perform_test
4 changes: 4 additions & 0 deletions tests/probes/maskattr/test_object_entity_nomask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "file" || return 255

name=$(basename $0 .sh)
Expand All @@ -27,3 +28,6 @@ echo "Testing syschar values."
[ "$($XPATH $result 'string(/oval_results/results/system/oval_system_characteristics/system_data/unix-sys:file_item/unix-sys:filepath)')" == "/etc/passwd" ]

rm $result
}

perform_test
4 changes: 4 additions & 0 deletions tests/probes/rpmverify/test_not_equals_operation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "rpmverify" || return 255

name=$(basename $0 .sh)
Expand All @@ -23,3 +24,6 @@ echo "Testing syschar values."
[ "$($XPATH $result 'count(/oval_results/results/system/oval_system_characteristics/collected_objects/object[@id="oval:x:obj:2"]/reference)')" == "1" ]

rm $result
}

perform_test
3 changes: 3 additions & 0 deletions tests/probes/sysctl/test_sysctl_probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "sysctl" || return 255

result=`mktemp`
Expand All @@ -17,4 +18,6 @@ assert_exists 1 "/oval_results/results/system/oval_system_characteristics/system

rm $result
rm $stderr
}

perform_test
4 changes: 3 additions & 1 deletion tests/probes/sysctl/test_sysctl_probe_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set -e -o pipefail

function perform_test {
probecheck "sysctl" || return 255

name=$(basename $0 .sh)
Expand Down Expand Up @@ -34,5 +35,6 @@ sed -i -E "/^E: lt-probe_sysctl: Can't read sysctl value from /d" "$stderr"
[ ! -s $stderr ]

rm $stderr $result $ourNames $sysctlNames
}


perform_test

0 comments on commit 3842789

Please sign in to comment.