Skip to content

Commit

Permalink
Adding URL existence tests
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Farley <[email protected]>
  • Loading branch information
adamfarley committed Dec 13, 2024
1 parent 56a5566 commit c3d2beb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions sbin/common/lib/functionLibrary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
14 changes: 13 additions & 1 deletion sbin/common/lib/functionLibraryTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3d2beb

Please sign in to comment.