Skip to content

Commit 44e94a1

Browse files
committed
Fix webhook regression: allow -1 to ignore status
1 parent 66320a6 commit 44e94a1

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

cmd/git-sync/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ func main() {
294294
}
295295

296296
if *flWebhookURL != "" {
297-
if *flWebhookStatusSuccess <= 0 {
298-
fmt.Fprintf(os.Stderr, "ERROR: --webhook-success-status must be greater than 0\n")
297+
if *flWebhookStatusSuccess < -1 {
298+
fmt.Fprintf(os.Stderr, "ERROR: --webhook-success-status must be a valid HTTP code or -1\n")
299299
flag.Usage()
300300
os.Exit(1)
301301
}

test_e2e.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,9 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
658658
pass
659659

660660
##############################################
661-
# Test webhook
661+
# Test webhook success
662662
##############################################
663-
testcase "webhook"
663+
testcase "webhook-success"
664664
freencport
665665
# First sync
666666
echo "$TESTCASE 1" > "$REPO"/file
@@ -671,6 +671,7 @@ GIT_SYNC \
671671
--repo="file://$REPO" \
672672
--root="$ROOT" \
673673
--webhook-url="http://127.0.0.1:$NCPORT" \
674+
--webhook-success-status=200 \
674675
--dest="link" \
675676
> "$DIR"/log."$TESTCASE" 2>&1 &
676677
# check that basic call works
@@ -700,6 +701,33 @@ fi
700701
# Wrap up
701702
pass
702703

704+
##############################################
705+
# Test webhook fire-and-forget
706+
##############################################
707+
testcase "webhook-fire-and-forget"
708+
freencport
709+
# First sync
710+
echo "$TESTCASE 1" > "$REPO"/file
711+
git -C "$REPO" commit -qam "$TESTCASE 1"
712+
GIT_SYNC \
713+
--logtostderr \
714+
--v=5 \
715+
--repo="file://$REPO" \
716+
--root="$ROOT" \
717+
--webhook-url="http://127.0.0.1:$NCPORT" \
718+
--webhook-success-status=-1 \
719+
--dest="link" \
720+
> "$DIR"/log."$TESTCASE" 2>&1 &
721+
# check that basic call works
722+
{ (echo -e "HTTP/1.1 404 Not Found\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
723+
NCPID=$!
724+
sleep 3
725+
if kill -0 $NCPID > /dev/null 2>&1; then
726+
fail "webhook 1 not called, server still running"
727+
fi
728+
# Wrap up
729+
pass
730+
703731
##############################################
704732
# Test http handler
705733
##############################################

0 commit comments

Comments
 (0)