Fix webhook regression: allow -1 to ignore status

This commit is contained in:
Tim Hockin 2020-09-25 11:03:04 -07:00
parent 66320a6b92
commit 44e94a16b0
2 changed files with 32 additions and 4 deletions

View File

@ -294,8 +294,8 @@ func main() {
}
if *flWebhookURL != "" {
if *flWebhookStatusSuccess <= 0 {
fmt.Fprintf(os.Stderr, "ERROR: --webhook-success-status must be greater than 0\n")
if *flWebhookStatusSuccess < -1 {
fmt.Fprintf(os.Stderr, "ERROR: --webhook-success-status must be a valid HTTP code or -1\n")
flag.Usage()
os.Exit(1)
}

View File

@ -658,9 +658,9 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
pass
##############################################
# Test webhook
# Test webhook success
##############################################
testcase "webhook"
testcase "webhook-success"
freencport
# First sync
echo "$TESTCASE 1" > "$REPO"/file
@ -671,6 +671,7 @@ GIT_SYNC \
--repo="file://$REPO" \
--root="$ROOT" \
--webhook-url="http://127.0.0.1:$NCPORT" \
--webhook-success-status=200 \
--dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
# check that basic call works
@ -700,6 +701,33 @@ fi
# Wrap up
pass
##############################################
# Test webhook fire-and-forget
##############################################
testcase "webhook-fire-and-forget"
freencport
# First sync
echo "$TESTCASE 1" > "$REPO"/file
git -C "$REPO" commit -qam "$TESTCASE 1"
GIT_SYNC \
--logtostderr \
--v=5 \
--repo="file://$REPO" \
--root="$ROOT" \
--webhook-url="http://127.0.0.1:$NCPORT" \
--webhook-success-status=-1 \
--dest="link" \
> "$DIR"/log."$TESTCASE" 2>&1 &
# check that basic call works
{ (echo -e "HTTP/1.1 404 Not Found\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
NCPID=$!
sleep 3
if kill -0 $NCPID > /dev/null 2>&1; then
fail "webhook 1 not called, server still running"
fi
# Wrap up
pass
##############################################
# Test http handler
##############################################