Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Adding shellcheck to openverse-api (#922)

MustkimKhatik043b319091ac
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 72fca94ca..69c62bf93 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -47,3 +47,7 @@ repos:
hooks:
- id: prettier
types: [yaml]
+ - repo: https://github.com/koalaman/shellcheck-precommit
+ rev: v0.8.0
+ hooks:
+ - id: shellcheck
diff --git a/api/test/run_test.sh b/api/test/run_test.sh
index 9e6223300..b7475f838 100755
--- a/api/test/run_test.sh
+++ b/api/test/run_test.sh
@@ -9,20 +9,20 @@ endcol="\e[0m"
# $ ./test/run_test.sh test/audio_integration_test.py
# ```
if [ $# -ge 1 ]; then
- TEST_ARG="$@"
+ TEST_ARG=( "$@" )
else
- TEST_ARG="test/"
+ TEST_ARG=( "test/" )
fi
PYTHONWARNINGS="ignore:Unverified HTTPS request" \
PYTHONPATH=. \
-pytest -s --disable-pytest-warnings $TEST_ARG
+pytest -s --disable-pytest-warnings "${TEST_ARG[@]}"
succeeded=$?
if [[ $succeeded -eq 0 ]]; then
- printf "${green}:-) All tests passed${endcol}\n"
+ printf "%b:-) All tests passed${endcol}\n" "${green}"
else
- printf "\n\n${red}:'( Some tests did not pass${endcol}\n"
+ printf "\n\n%b:'( Some tests did not pass${endcol}\n" "${red}"
printf "Hint: \`just logs [service]\` will print the Docker logs and may be helpful for debugging.\n\n"
fi
exit $succeeded
diff --git a/ingestion_server/test/run_test.sh b/ingestion_server/test/run_test.sh
index 616a66275..c92774f64 100755
--- a/ingestion_server/test/run_test.sh
+++ b/ingestion_server/test/run_test.sh
@@ -9,19 +9,19 @@ endcol="\e[0m"
# $ ./test/run_test.sh test/unit_test.py
# ```
if [ $# -ge 1 ]; then
- TEST_ARG="$@"
+ TEST_ARG=( "$@" )
else
- TEST_ARG="test/"
+ TEST_ARG=( "test/" )
fi
PYTHONWARNINGS="ignore:Unverified HTTPS request" \
PYTHONPATH=. \
-pytest -sx -vv --disable-pytest-warnings $TEST_ARG
+pytest -sx -vv --disable-pytest-warnings "${TEST_ARG[@]}"
succeeded=$?
if [[ $succeeded -eq 0 ]]; then
- printf "${green}:-) All tests passed${endcol}\n"
+ printf "%b:-) All tests passed${endcol}\n" "${green}"
else
- printf "${red}:'( Some tests did not pass${endcol}\n"
+ printf "\n\n%b:'( Some tests did not pass${endcol}\n" "${red}"
fi
exit $succeeded
diff --git a/ingestion_server/test/update_mocks.sh b/ingestion_server/test/update_mocks.sh
index c4107642d..8efef24e6 100755
--- a/ingestion_server/test/update_mocks.sh
+++ b/ingestion_server/test/update_mocks.sh
@@ -40,4 +40,4 @@ docker run \
green="\e[32m"
endcol="\e[0m"
-printf "${green}:-) Exported new mock data${endcol}\n"
+printf "%b:-) Exported new mock data${endcol}\n" "${green}"
diff --git a/load_sample_data.sh b/load_sample_data.sh
index fe1c3fb47..9e50aee2d 100755
--- a/load_sample_data.sh
+++ b/load_sample_data.sh
@@ -112,8 +112,8 @@ just wait-for-index "audio"
set +e
while true; do
just ingest-upstream "image" "init"
- just wait-for-index "image-init"
- if [ $? -eq 0 ]; then
+ if just wait-for-index "image-init"
+ then
break
fi
((c++)) && ((c==3)) && break