From 68337ae510e02f884772d63a5a933f6177108e75 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 13 Jul 2020 18:25:38 -0400 Subject: Remove core nexus code * Use nexus_bash package --- test.sh | 113 +++++++++++----------------------------------------------------- 1 file changed, 18 insertions(+), 95 deletions(-) diff --git a/test.sh b/test.sh index 99a78de..d5fd4a1 100755 --- a/test.sh +++ b/test.sh @@ -5,97 +5,6 @@ RTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source "${RTDIR}"/test_config.sh -get_data_exists() { - local url - local response - - url="${test_data_remote}/$1" - if [[ -z $url ]]; then - echo "get_data_exists: requires a path relative to $test_data_remote" - exit 1 - fi - - response=$(curl -s --head "$url" | head -n 1 | awk '{print $2}') - if (( $response != 200 )); then - return 1; - fi - return 0; -} - -get_data() { - local url - local filename - - if [[ ! -d "${test_data}" ]]; then - mkdir -p "${test_data}" - fi - - url="${test_data_remote}/$1" - if [[ -z $url ]]; then - echo "get_data: requires a path relative to $test_data_remote" - exit 1 - fi - - filename=$(basename $url) - if ! get_data_exists "$1"; then - echo "${url}: not found on remote server" >&2 - return 1 - fi - - if ! (cd $test_data && curl -L -O "$url"); then - echo "Could not download data" >&2 - return 1 - fi - - echo "$test_data/$filename"; -} - -put_data() { - local url - local filename - - url="${test_data_remote}/$2" - filename="$1" - - if [[ -z $url ]]; then - echo "put_data: requires a path relative to $test_data_remote" - return 1 - fi - - if ! curl -s --user "${test_data_remote_auth}" --upload-file "${filename}" "${url}/${filename}"; then - echo "Could not upload '${filename}' to '${url}'" >&2 - return 1 - fi - - return 0 -} - -put_result() { - local src; - local dest; - src="$1" - dest="$2" - - if [[ ! -d "$src" ]]; then - echo "push_result: source directory does not exist: ${src}" >&2 - return 1 - fi - - if [[ -z "$dest" ]]; then - echo "push_result: requires a destination relative to ${test_data_remote}" >&2 - return 1 - fi - - for f in $(find "${src}" -type f); do - echo "Uploading '$f' to '$dest'" - if ! put_data "$f" "${dest}"; then - echo "Failed uploading '$src' to '$dest'" >&2 - return 1 - fi - done; - return 0 -} - read_tests() { for f in "${RTDIR}"/tests/test_*; do source "$f" || return 0 @@ -142,11 +51,10 @@ run_tests() { done # Upload all artifacts in all test directories - if [[ -n "$test_data_remote_auth" ]]; then + if [[ -n "$NEXUS_AUTH" ]]; then echo - for (( i=0; i < ${total_tests}; i++ )); do - test_case="${tests[i]}" - put_result ${test_case} ${test_data_upload} + for test_case in "${tests[@]}"; do + nexus_raw_upload_dir "${test_case}" "${test_data_upload}" done fi } @@ -162,7 +70,22 @@ show_stats() { printf "\n%d test(s): %d passed, %d failed\n" ${total_tests} ${total_passed} ${total_failed} } +setup_deps() { + if [[ ! -d nexus_bash ]]; then + git clone https://github.com/jhunkeler/nexus_bash + fi + + if [[ -n "$test_dep_nexus_bash_rev" ]]; then + (cd nexus_bash && git checkout $test_dep_nexus_bash_rev) &>/dev/null + else + (cd nexus_bash && git pull) &>/dev/null + fi + + source nexus_bash/nexus_bash.sh +} + # main program +setup_deps check_runtime if read_tests; then -- cgit From dc6dcc66e8ad0d768c6fc0c1c32bd31e95060088 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 13 Jul 2020 18:25:58 -0400 Subject: Update nexus config variables --- test_config.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test_config.sh b/test_config.sh index 7746a6d..3c19303 100644 --- a/test_config.sh +++ b/test_config.sh @@ -1,9 +1,10 @@ +NEXUS_URL=https://nx.astroconda.org +NEXUS_AUTH=${NEXUS_AUTH:-} test_program="${RTDIR}/splitfits" test_program_version="$(git describe --always --tags --long)" test_data="${RTDIR}/data" -test_data_remote=https://nx.astroconda.org/repository -test_data_remote_auth=${test_data_remote_auth:-} -test_data_upload="generic/spb-splitfits" +test_data_upload="repository/generic/spb-splitfits" +test_dep_nexus_bash_rev=a2586e952bb9e5e70a2d62c55337574d7086b9a0 if [[ $CIRCLECI == "true" ]]; then test_data_upload="${test_data_upload}/ci/${CIRCLE_BRANCH}_${CIRCLE_JOB}/${CIRCLE_BUILD_NUM}/${test_program_version}" else -- cgit From 5245975f67212fdae08033e13c0c7d2b6db1256e Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 13 Jul 2020 18:26:21 -0400 Subject: Update test code --- tests/test_split.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_split.sh b/tests/test_split.sh index 13ec5a9..562876a 100644 --- a/tests/test_split.sh +++ b/tests/test_split.sh @@ -1,7 +1,7 @@ test_splitfits_data1() { local datafile - datafile=$(get_data generic/fits/sample.fits) + datafile=$(nexus_raw_download repository/generic/fits/sample.fits) [[ ! -f ${datafile} ]] && return 1 if ! ${test_program} -o ${test_case} ${datafile}; then @@ -14,7 +14,7 @@ test_splitfits_data1() { test_splitfits_combine_data1() { local datafile - datafile=$(get_data generic/fits/sample.fits) + datafile=$(nexus_raw_download repository/generic/fits/sample.fits) [[ ! -f ${datafile} ]] && return 1 if ! ${test_program} -o ${test_case} ${datafile}; then -- cgit From 8225c761bb911d2c970cb73ba7b527a1002a22db Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 13 Jul 2020 22:49:34 -0400 Subject: Fail if output is different --- tests/test_split.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_split.sh b/tests/test_split.sh index 562876a..45d9abd 100644 --- a/tests/test_split.sh +++ b/tests/test_split.sh @@ -8,6 +8,11 @@ test_splitfits_data1() { return 1 fi + find . -regex '.*\.part_[0-9]+' | xargs -I'{}' cat '{}' >> streamed.fits + if ! diff ${datafile} streamed.fits; then + return 1 + fi + return 0 } -- cgit From 67b69cd38f0f15078bf832e91f7e4196649ffcfe Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 13 Jul 2020 23:07:57 -0400 Subject: Version sort on find output --- tests/test_split.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_split.sh b/tests/test_split.sh index 45d9abd..c049d18 100644 --- a/tests/test_split.sh +++ b/tests/test_split.sh @@ -8,8 +8,10 @@ test_splitfits_data1() { return 1 fi - find . -regex '.*\.part_[0-9]+' | xargs -I'{}' cat '{}' >> streamed.fits - if ! diff ${datafile} streamed.fits; then + files=$(find . -regex '.*\.part_[0-9]+' | sort -V) + cat $files > streamed.fits + + if ! diff -q ${datafile} streamed.fits; then return 1 fi -- cgit