Skip to content

Commit

Permalink
tests: fix document-interfaces-url test (canonical#14633)
Browse files Browse the repository at this point in the history
* Tests: fix document-interfaces-url test

Currently the servers are returning http status code 500 randomly making
the test fail. Also sometimes the server is taking to long to send the
response so a connection timeout is needed.

* Update tests/main/document-interfaces-url/task.yaml

Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>

* Update tests/main/document-interfaces-url/task.yaml

Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>

---------

Co-authored-by: Zeyad Yasser <zeyady98@gmail.com>
  • Loading branch information
sergiocazzolato and ZeyadYasser authored Oct 18, 2024
1 parent 9334749 commit 9380736
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions tests/main/document-interfaces-url/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ execute: |
for _ in $(seq $num_retries); do
# Make a HEAD request to the URL and capture the HTTP status code
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" "$url")
status_code=$(curl -o /dev/null -s -w "%{http_code}\n" --connect-timeout 10 "$url")
# Check if the status code is in the 2xx range
# If the status code is 2xx the url is ok
if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 300 ]; then
return 0
fi
# If status code is 500 means the server is not working properly
if [ "$status_code" == 500 ]; then
return 0
fi
done
# If status code 4xx is returned then the page is not found, return error
return 1
}
Expand Down Expand Up @@ -60,20 +66,23 @@ execute: |
}
bad=""
nodoc=""
# Loop through all interfaces
for iface in $(snap interface --all | awk 'NR > 1 {print $1}' | tr '\n' ' '); do
printf "Checking presence of documentation url for interface %s\n" "'$iface':"
url="https://snapcraft.io/docs/$iface-interface"
echo "Checking presence of documentation url for interface $iface"
url="https://snapcraft.io/docs/${iface}-interface"
actual="$( snap interface "$iface" )"
if MATCH "documentation: $url" <<<"$actual"; then
if exclude "$iface" || webpage_exists "$url"; then
echo "ok"
if exclude "$iface"; then
echo "Interface $iface excluded"
elif webpage_exists "$url"; then
echo "Interface $iface has webpage"
else
bad=1
nodoc="$nodoc $iface"
echo "ERROR: Could not find help url for $iface at $url"
fi
else
bad=1
bad="$bad $iface"
echo
echo "ERROR: The output of 'snap interface $iface' does not contain a documentation entry for $url:"
echo "----------------"
Expand All @@ -82,4 +91,13 @@ execute: |
fi
done
if [ -n "$bad" ]; then
echo "The output of the following interfaces do not contain a documentation entry: $bad"
fi
if [ -n "$nodoc" ]; then
echo "The following interfaces do not have a documentation webpage: $nodoc"
fi
test -z "$bad"
test -z "$nodoc"

0 comments on commit 9380736

Please sign in to comment.