Refactor run_pypi_tests.sh

Split into separate files to support running locally.

Add extra output on shell tests.
This commit is contained in:
Jon Grace-Cox
2022-08-24 12:53:01 -07:00
parent f5b6815ef1
commit de29275c76
4 changed files with 100 additions and 66 deletions

View File

@@ -7,3 +7,5 @@ COPY requirements.txt ./
RUN pip install -r ./requirements.txt
COPY run_docker_tests.sh ./
COPY run_pypi_tests.sh ./
COPY helpers.sh ./
COPY shell_tests.sh ./

14
docker/test/helpers.sh Normal file
View File

@@ -0,0 +1,14 @@
error() {
echo "==============================================================================="
echo " An error was encountered."
echo "==============================================================================="
}
check_rc() {
if [[ $? -ne 0 ]]; then
error
exit 1
fi
}
export TEST_FILES="${PROJECT_DIR:-}/test_files"

View File

@@ -1,78 +1,16 @@
#!/bin/bash
error() {
echo "==============================================================================="
echo " An error was encountered."
echo "==============================================================================="
}
source "${SOURCE_DIR:-.}/helpers.sh" || { echo "Failed to load helpers." ; exit 1 ; }
check_rc() {
if [[ $? -ne 0 ]]; then
error
exit 1
fi
}
TEST_FILES="/test_files"
if [[ -z {$VERSION} ]] || [[ ${VERSION} = latest ]]; then
if [[ -z ${VERSION} ]] || [[ ${VERSION} = latest ]]; then
version_str=""
else
version_str="==$VERSION"
fi
echo -n "Installing anybadge${version_str}... "
pip install anybadge${version_str} > "${TEST_FILES}/pip_install.log" 2>&1
pip install "anybadge${version_str}" > "${TEST_FILES}/pip_install.log" 2>&1
check_rc
echo "OK"
installed_version=$(pip freeze | grep -e "^anybadge==" | sed 's/^.*==//' )
datestamp=$(date '+%Y-%m-%d_%H%M%S')
TEST_FILES="${TEST_FILES}/${installed_version}_${datestamp}"
echo -n "Creating test directory: ${TEST_FILES} "
mkdir -p ${TEST_FILES}
check_rc
echo "OK"
# Command line tests
anybadge --help > "${TEST_FILES}/test_help_text.txt" && check_rc
anybadge --label="Label" --value="Value" --file "${TEST_FILES}/test_command_line.svg" && check_rc
# Python tests
python > "${TEST_FILES}/test_python_console.log" <<EOF
import anybadge
badge = anybadge.Badge(label="Label", value="Value")
badge.write_badge(file_path="${TEST_FILES}/test_python_1.svg")
print(badge)
EOF
check_rc
# Start server
echo -n "Starting server... "
anybadge-server > "${TEST_FILES}/server_start.log" 2>&1 &
server_pid=$!
echo "OK - Started server with pid ${server_pid}"
sleep 1
kill -0 ${server_pid}
check_rc
# Test server
echo -n "Testing server badge... "
curl "http://localhost:8000/?label=Project%20Awesomeness&value=110%" -o "${TEST_FILES}/test_server.svg" --silent
check_rc
echo "OK"
echo -n "Testing server index page... "
curl "http://localhost:8000" -o "${TEST_FILES}/test_server_index.html" --silent
check_rc
echo "OK"
# Stop server
echo -n "Stopping server... "
kill $server_pid
check_rc
echo "OK"
"${SOURCE_DIR:-.}/shell_tests.sh"

80
docker/test/shell_tests.sh Executable file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
source "${SOURCE_DIR:-.}/helpers.sh" || { echo "Failed to load helpers." ; exit 1 ; }
echo -n "Getting installed version... "
# Get installed version
installed_version=$(pip freeze | grep -e "^anybadge==" | sed 's/^.*==//' )
if [[ -z ${installed_version} ]]; then
installed_version=$(anybadge --version)
fi
echo "OK"
echo "Installed version: ${installed_version}"
# Create test directory
datestamp=$(date '+%Y-%m-%d_%H%M%S')
TEST_FILES="${TEST_FILES}/${installed_version}_${datestamp}"
echo -n "Creating test directory: ${TEST_FILES} "
mkdir -p ${TEST_FILES}
check_rc
echo "OK"
# Command line tests
echo -n "Testing --help... "
anybadge --help > "${TEST_FILES}/test_help_text.txt"
check_rc
echo "OK"
echo -n "Testing basic call... "
anybadge --label="Label" --value="Value" --file "${TEST_FILES}/test_command_line.svg"
check_rc
echo "OK"
echo -n "Testing python -m call... "
python -m anybadge --label="Label" --value="Value" --file "${TEST_FILES}/test_m_command_line.svg"
check_rc
echo "OK"
# Python tests
echo -n "Testing python api call... "
python > "${TEST_FILES}/test_python_console.log" <<EOF
import anybadge
badge = anybadge.Badge(label="Label", value="Value")
badge.write_badge(file_path="${TEST_FILES}/test_python_1.svg")
print(badge)
EOF
check_rc
echo "OK"
# Start server
echo -n "Starting server... "
anybadge-server > "${TEST_FILES}/server_start.log" 2>&1 &
server_pid=$!
echo "OK - Started server with pid ${server_pid}"
sleep 1
kill -0 ${server_pid}
check_rc
# Test server
echo -n "Testing server badge... "
curl "http://localhost:8000/?label=Project%20Awesomeness&value=110%" -o "${TEST_FILES}/test_server.svg" --silent
check_rc
echo "OK"
echo -n "Testing server index page... "
curl "http://localhost:8000" -o "${TEST_FILES}/test_server_index.html" --silent
check_rc
echo "OK"
# Stop server
echo -n "Stopping server... "
kill $server_pid
check_rc
echo "OK"