Changeset View
Changeset View
Standalone View
Standalone View
tests/test_image.sh
- This file was moved from scripts/test_docker_image.sh.
#!/bin/bash | #!/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 | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
DOCKER_IMAGE="maven-index-exporter" | DOCKER_IMAGE="softwareheritage/maven-index-exporter" | ||||
LOG=test_docker_image.log | 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) | REPO_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | ||||
cd $OLD_DIR | |||||
WORK_DIR=$REPO_DIR/tests/repository_test | WORK_DIR=$REPO_DIR/tests/repository_test | ||||
EXPORT_DIR=$WORK_DIR/export | EXPORT_DIR=$WORK_DIR/export | ||||
PUBLISH_DIR=$REPO_DIR/tests/publish | |||||
# First clean up and remove any docker image with our own name | # clean up publish directory | ||||
docker rmi $DOCKER_IMAGE >>$LOG 2>&1 | rm -rf $PUBLISH_DIR/* | ||||
RET=$? | mkdir -p $PUBLISH_DIR | ||||
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 | |||||
# This will mock out the download part of the python code | |||||
export MVN_IDX_EXPORTER_BASE_URL='test://example.org' | |||||
# Run the image on the maven indexes. | # 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 \ | |||||
-e MVN_IDX_EXPORTER_BASE_URL \ | |||||
$DOCKER_IMAGE >>$LOG 2>&1 | |||||
# Assert exported text files are there, with the correct content. | # Assert exported text files are there, with the correct content. | ||||
EXPORT_FILE=$(ls $EXPORT_DIR/*.fld) | EXPORT_FILE=$(ls $EXPORT_DIR/*.fld) | ||||
if [[ -e $EXPORT_FILE ]]; then | if [[ -e $EXPORT_FILE ]]; then | ||||
echo "PASS: file [$EXPORT_FILE] has been created." | echo "PASS: file [$EXPORT_FILE] has been created." | ||||
else | else | ||||
echo "FAIL: file [$EXPORT_FILE] has NOT been created." | echo "FAIL: file [$EXPORT_FILE] has NOT been created." | ||||
exit 20 | exit 20 | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
FIELDS=$(grep "value al.aldi|sprova4j|0.1.1|NA|pom" $EXPORT_FILE | wc -l) | FIELDS=$(grep "value al.aldi|sprova4j|0.1.1|NA|pom" $EXPORT_FILE | wc -l) | ||||
if [[ $FIELDS -eq 1 ]]; then | if [[ $FIELDS -eq 1 ]]; then | ||||
echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.1.pom." | echo "PASS: file [$EXPORT_FILE] has sprova4j-0.1.1.pom." | ||||
else | else | ||||
echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.1.pom." | echo "FAIL: file [$EXPORT_FILE] has NOT sprova4j-0.1.1.pom." | ||||
exit 20 | exit 20 | ||||
fi | fi | ||||
PUBLISH_FILE=$PUBLISH_DIR/export.fld | |||||
if [[ -f $PUBLISH_FILE ]]; then | |||||
echo "PASS: file [$PUBLISH_FILE] exists." | |||||
else | |||||
echo "FAIL: file [$PUBLISH_FILE] does not exist." | |||||
exit 20 | |||||
fi | |||||
# Cleanup | # Cleanup | ||||
rm -rf $EXPORT_DIR | rm -rf $EXPORT_DIR | ||||
cd $OLD_DIR | cd $OLD_DIR |