diff --git a/sbin/common/lib/functionLibrary.sh b/sbin/common/lib/functionLibrary.sh index f42b21f78..6fc8b3eac 100644 --- a/sbin/common/lib/functionLibrary.sh +++ b/sbin/common/lib/functionLibrary.sh @@ -85,10 +85,12 @@ function doesThisURLExist() { spiderOutput=1 if command -v wget &> /dev/null; then - wget --spider -q ${source} 2> /dev/null + info "Using wget to verify URL exists." + wget --spider -q ${1} 2> /dev/null spiderOutput=$? elif command -v curl &> /dev/null; then - curl -I ${source} -s | grep "200 OK" -q + info "Using curl to verify URL exists." + curl -I ${1} -s | grep "200 OK" -q spiderOutput=$? else echo "Error: Neither wget nor curl could be found when downloading this file: ${source}" diff --git a/sbin/common/lib/functionLibraryTests.sh b/sbin/common/lib/functionLibraryTests.sh index 10b2ff2b8..3d32e7fbe 100644 --- a/sbin/common/lib/functionLibraryTests.sh +++ b/sbin/common/lib/functionLibraryTests.sh @@ -50,7 +50,19 @@ function checkFileShaTests(){ # doesThisURLExist function doesThisURLExistTests(){ - return 0 + # Does it pass when it should? + doesThisURLExist "https://adoptium.net/index.html" + testResults "doesThisURLExistTest 1" "$?" + + # Does it fail when it should? + doesThisURLExist "https://thisurlshouldneverexist123456gibberish.com" &> /dev/null + [[ "$?" != "0" ]] + testResults "doesThisURLExistTest 2" "$?" + + # And does it fail when it's not even a URL? + doesThisURLExist "thisnonurlshouldneverexist123456gibberish" &> /dev/null + [[ "$?" != "0" ]] + testResults "doesThisURLExistTest 3" "$?" } # downloadFile