Skip to content

Commit 40191ad

Browse files
xxc3nsoredxxCogitri
authored andcommitted
Test for expected vs unexpected 401
AUTH_SKIPS is a list of services for which an HTTP 401 is an expected response if an auth token isn't given. 401 for a service outside of the list means a changed/broken API. Invert the `if ! diff then fail else success` for readability.
1 parent 5c2ccaf commit 40191ad

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

test/.test.sh.swp

16 KB
Binary file not shown.

test/test.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DL_DIR="$(mktemp -q -d /tmp/wgetpaste_test.XXXXX)"
1212
# codepad: timing out
1313
HARD_SKIPS=('codepad')
1414
HARD_SKIP_COUNT=0
15+
# Services expected to require an authorization token
16+
AUTH_SKIPS=('gists' 'snippets')
1517
AUTH_SKIP_COUNT=0
1618
FAIL_SKIP_COUNT=0
1719
DL_COUNT=0
@@ -47,9 +49,17 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
4749
# Skip failed posts (eg, not authorized for GitHub/GitLab, service error)
4850
if [ "$STATUS" -ne 0 ]; then
4951
if (grep -iq "HTTP.*401.*Unauthorized" "$ERROR_LOG"); then
50-
echo "SKIPPING, needs authorization..."
51-
AUTH_SKIP_COUNT=$((AUTH_SKIP_COUNT + 1))
52-
rm "$ERROR_LOG"
52+
# Check if a 401 is expected behavior. If it isn't, mark as fail
53+
for as in "${AUTH_SKIPS[@]}"; do
54+
if [ "$serv" == "$as" ]; then
55+
echo "SKIPPING, needs authorization..."
56+
AUTH_SKIP_COUNT=$((AUTH_SKIP_COUNT + 1))
57+
rm "$ERROR_LOG"
58+
continue 2
59+
fi
60+
done
61+
echo "UNEXPECTED 401, skipping..."
62+
FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1))
5363
else
5464
echo "SKIPPING, failed to post..."
5565
FAIL_SKIP_COUNT=$((FAIL_SKIP_COUNT + 1))
@@ -81,11 +91,11 @@ fi
8191
for dl_file in "$DL_DIR"/*.txt; do
8292
echo -n "Testing file $dl_file: "
8393
# Ignore missing trailing newline in downloaded file
84-
if ! (diff -q -Z "$TEST_FILE" "$dl_file" &>/dev/null); then
94+
if (diff -q -Z "$TEST_FILE" "$dl_file" &>/dev/null); then
95+
echo "SUCCESS!"
96+
else
8597
echo "FAILED!"
8698
DL_MISMATCH=$((DL_MISMATCH + 1))
87-
else
88-
echo "SUCCESS!"
8999
fi
90100
done
91101

0 commit comments

Comments
 (0)