Skip to content

Commit

Permalink
Fix webhook regression: allow -1 to ignore status
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Sep 25, 2020
1 parent 66320a6 commit 44e94a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/git-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 30 additions & 2 deletions test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
##############################################
Expand Down

0 comments on commit 44e94a1

Please sign in to comment.