Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansev committed Feb 19, 2024
1 parent 7b25aa3 commit 583d355
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
7 changes: 4 additions & 3 deletions tests/003_find.test/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

clean_logs () { rm -f log.txt cmdout.txt cmderr.txt &> /dev/null; }
clean_logs () { rm -f log.txt cmdout.txt &> /dev/null; }

clean_logs
export ALIENPY_DEBUG=1 ALIENPY_DEBUG_FILE=log.txt ALIENPY_DEBUG_APPEND=1
Expand All @@ -9,8 +9,9 @@ TEST_SCRIPT="$(realpath ${0})"
THIS_TEST="$(basename $(dirname ${TEST_SCRIPT}))/$(basename ${TEST_SCRIPT})"

GOOD_RESULT="4"
alien.py find '/alice/cern.ch/user/a/admin/referenceData .log' > cmdout.txt 2> cmderr.txt || { echo "Error running alien_find in ${THIS_TEST}!"; cat cmderr.txt; exit 1; }
EXITCODE="0"
alien.py find '/alice/cern.ch/user/a/admin/referenceData .log' &> cmdout.txt || { EXITCODE="${?}"; echo "Error running alien_find in ${THIS_TEST}!"; cat cmdout.txt; exit "${EXITCODE}"; }

FILE_COUNT=$(grep referenceData cmdout.txt | wc -l)
[[ "${FILE_COUNT}" -eq "${GOOD_RESULT}" ]] && { echo "OK"; clean_logs; } || { echo "Wrong count of files in ${THIS_TEST}"; exit 1; }
[[ "${FILE_COUNT}" -eq "${GOOD_RESULT}" ]] && { clean_logs; exit "${EXITCODE}"; } || { echo "Wrong count of files in ${THIS_TEST}"; exit 1; }

2 changes: 1 addition & 1 deletion tests/004_cp.test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ THIS_TEST="$(basename $(dirname ${TEST_SCRIPT}))/$(basename ${TEST_SCRIPT})"

dst="referenceData.xml"
[[ -f "${dst}" ]] && rm -f ${dst}
alien.py cp -retry 2 /alice/cern.ch/user/a/admin/referenceData/referenceData.xml "file:${dst}" &> out.log && { echo "OK"; clean_logs; } || { EXITCODE="${?}"; echo "Failed download in ${THIS_TEST} with code ${EXITCODE}"; cat out.log; exit ${EXITCODE}; }
alien.py cp -retry 2 /alice/cern.ch/user/a/admin/referenceData/referenceData.xml "file:${dst}" &> out.log && { clean_logs; } || { EXITCODE="${?}"; echo "Failed download in ${THIS_TEST} with code ${EXITCODE}"; cat out.log; exit ${EXITCODE}; }

4 changes: 3 additions & 1 deletion tests/005_cp_dir.test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ echo "OK"
# get the number of uploaded files
FOUND_REMOTE_FILES=$(alien.py find "${TESTDIR_REMOTE} .log" | grep ${TESTDIR_REMOTE} | wc -l)
GOOD_RESULT="4"
[[ "${FOUND_REMOTE_FILES}" -eq "${GOOD_RESULT}" ]] && { echo "OK"; } || { echo "Wrong count of files in ${THIS_TEST} but operations succesful so far!! Send the logs to developer!"; exit 1; }
echo -ne "Checking correct number of uploaded files .. "
[[ "${FOUND_REMOTE_FILES}" -eq "${GOOD_RESULT}" ]] || { echo "Wrong count of files in ${THIS_TEST} but operations succesful so far!! Send the logs to developer!"; exit 1; }
echo "OK"

# clean ci dir
alienpy_clean_testdir "${TESTDIR_REMOTE}" "${TESTDIR_LOCAL}"
Expand Down
21 changes: 16 additions & 5 deletions tests/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ shift

[[ "${ARG}" == "ci-tests" ]] && IS_CI="1"

SCRIPT_DIR=$(realpath --canonicalize-existing $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )) #"
SCRIPT_DIR="$(realpath --canonicalize-existing $( cd -- $( dirname -- ${BASH_SOURCE[0]} ) &> /dev/null && pwd ))"

test_dirlist=$(find "${SCRIPT_DIR}" -type d -name "*.test" | sort)

FAILED_TESTS="0"

for t in ${test_dirlist}; do
[[ -n "${IS_CI}" && "$(basename ${t})" == "002_env_tokens.test" ]] && continue;
TEST_NAME="$(basename ${t})"
[[ -n "${IS_CI}" && "${TEST_NAME}" == "002_env_tokens.test" ]] && continue;

echo "Running test : $(basename ${t})"
echo "Running test : ${TEST_NAME} ... "
pushd "${t}" &> /dev/null
./test.sh || { echo "Failed test, stopping testing"; break; }
./test.sh
EXITCODE="${?}"
if [[ ${EXITCODE} == "0" ]]; then
echo -e "OK\n"
else
(( FAILED_TESTS++ ))
echo -e "Failed test!!! Exitcode == ${EXITCODE}\n"
[[ -z "${IS_CI}" ]] && break;
fi
popd &> /dev/null
echo -e "END test : $(basename ${t})\n\n"
done

exit "${FAILED_TESTS}"

0 comments on commit 583d355

Please sign in to comment.