diff --git a/scripts/requirements.txt b/scripts/requirements.txt deleted file mode 100644 --- a/scripts/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -certifi==2021.5.30 -charset-normalizer==2.0.4 -docker==5.0.0 -idna==3.2 -pkg-resources==0.0.0 -requests==2.26.0 -six==1.16.0 -urllib3==1.26.6 -websocket-client==1.2.1 -click diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +publish/ diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,5 @@ +build-and-test: + ./build_and_test_image.sh + +test: + ./test_image.sh diff --git a/tests/build_and_test_image.sh b/tests/build_and_test_image.sh new file mode 100755 --- /dev/null +++ b/tests/build_and_test_image.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Copyright (C) 2021-2022 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +DOCKER_IMAGE="softwareheritage/maven-index-exporter" +LOG=test_docker_image.log + +# This script builds the docker image for maven-index-exporter, and +# executes it on a known set of indexes and checks the results in order +# to test the full tool chain. + +echo "Script started on `date +%Y%m%d_%H%M%S`." +echo "* Writing log to $LOG." + +# Find location of script directory +OLD_DIR=$(pwd) +REPO_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd $OLD_DIR + +# First clean up and remove any docker image with our own name +docker rmi $DOCKER_IMAGE >>$LOG 2>&1 +RET=$? +if [[ $RET -eq 0 ]]; then + echo "* Docker image [$DOCKER_IMAGE] deleted." +elif [[ $RET -eq 1 ]]; then + echo "* Docker image [$DOCKER_IMAGE] doesn't exist." +else + echo "Error when deleting docker image [$DOCKER_IMAGE]." +fi + +# Build the image and tag it as $DOCKER_IMAGE +cd $REPO_DIR/docker +echo "* Building docker image." +docker build . -t $DOCKER_IMAGE >>$LOG +RET=$? +if [[ $RET -eq 0 ]]; then + echo "PASS: docker build returned 0." +else + echo "FAIL: docker build returned $RET." + exit 20 +fi + +# Assert docker image has been created. +COUNT=$(docker images | grep -E "^$DOCKER_IMAGE\s" | wc -l) +if [[ $COUNT -eq 0 ]]; then + echo "FAIL: Docker image cannot be listed." + exit 10 +else + echo "PASS: Docker image is listed." +fi + +cd $OLD_DIR +./test_image.sh diff --git a/scripts/test_docker_image.sh b/tests/test_image.sh rename from scripts/test_docker_image.sh rename to tests/test_image.sh --- a/scripts/test_docker_image.sh +++ b/tests/test_image.sh @@ -1,63 +1,26 @@ #!/bin/bash -# Copyright (C) 2021 The Software Heritage developers +# Copyright (C) 2021-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -DOCKER_IMAGE="maven-index-exporter" +DOCKER_IMAGE="softwareheritage/maven-index-exporter" LOG=test_docker_image.log -# This script builds the docker image for maven-index-exporter, and -# executes it on a known set of indexes and checks the results in order -# to test the full tool chain. - -echo "Script started on `date +%Y%m%d_%H%M%S`." -echo "* Writing log to $LOG." - -# Find location of script directory -OLD_DIR=$(pwd) REPO_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) -cd $OLD_DIR - WORK_DIR=$REPO_DIR/tests/repository_test EXPORT_DIR=$WORK_DIR/export +PUBLISH_DIR=$REPO_DIR/tests/publish -# First clean up and remove any docker image with our own name -docker rmi $DOCKER_IMAGE >>$LOG 2>&1 -RET=$? -if [[ $RET -eq 0 ]]; then - echo "* Docker image [$DOCKER_IMAGE] deleted." -elif [[ $RET -eq 1 ]]; then - echo "* Docker image [$DOCKER_IMAGE] doesn't exist." -else - echo "Error when deleting docker image [$DOCKER_IMAGE]." -fi - - -# Build the image and tag it as $DOCKER_IMAGE -cd $REPO_DIR/docker -echo "* Building docker image." -docker build . -t $DOCKER_IMAGE --no-cache >>$LOG -RET=$? -if [[ $RET -eq 0 ]]; then - echo "PASS: docker build returned 0." -else - echo "FAIL: docker build returned $RET." - exit 20 -fi - -# Assert docker image has been created. -COUNT=$(docker images | grep -E "^$DOCKER_IMAGE\s" | wc -l) -if [[ $COUNT -eq 0 ]]; then - echo "FAIL: Docker image cannot be listed." - exit 10 -else - echo "PASS: Docker image is listed." -fi +# clean up publish directory +rm -rf $PUBLISH_DIR/* +mkdir -p $PUBLISH_DIR # Run the image on the maven indexes. -docker run -v $WORK_DIR:/work $DOCKER_IMAGE >>$LOG 2>&1 +docker run -v $WORK_DIR:/work \ + -v $PUBLISH_DIR:/publish \ + $DOCKER_IMAGE >>$LOG 2>&1 # Assert exported text files are there, with the correct content. EXPORT_FILE=$(ls $EXPORT_DIR/*.fld) @@ -117,5 +80,7 @@ fi # Cleanup +# clean up publish directory +rm -rf $PUBLISH_DIR/* rm -rf $EXPORT_DIR cd $OLD_DIR