From 44e94a16b069db610641bd69d2660baa8fe09f95 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 25 Sep 2020 11:03:04 -0700 Subject: [PATCH] Fix webhook regression: allow -1 to ignore status --- cmd/git-sync/main.go | 4 ++-- test_e2e.sh | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 5d5a0c8fb..68e556739 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -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) } diff --git a/test_e2e.sh b/test_e2e.sh index 34a27ae9b..9d3d728ac 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -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 ##############################################