From 6d98f420e7459d0e0a78cbe9e95c6307e8cdc248 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Wed, 23 Jan 2019 10:54:50 -0800 Subject: [PATCH 1/3] Add e2e test for webhook Test for #131 --- test_e2e.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test_e2e.sh b/test_e2e.sh index 22b2807..a4e91b6 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -89,6 +89,7 @@ function GIT_SYNC() { -u $(id -u):$(id -g) \ -v "$DIR":"$DIR" \ -v "$(pwd)/slow_git.sh":"/slow_git.sh" \ + --network="host" \ --rm \ e2e/git-sync:$(make -s version)__$(go env GOOS)_$(go env GOARCH) \ "$@" @@ -588,5 +589,49 @@ remove_sync_container wait pass +# Test webhook +testcase "webhook" +NCPORT=8888 +# First sync +echo "$TESTCASE 1" > "$REPO"/file +expected_depth="1" +git -C "$REPO" commit -qam "$TESTCASE 1" +GIT_SYNC \ + --logtostderr \ + --v=5 \ + --repo="$REPO" \ + --depth="$expected_depth" \ + --root="$ROOT" \ + --webhook-url="http://127.0.0.1:$NCPORT" \ + --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & +# check that basic call works +{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &} +NCPID=$! +sleep 3 +if kill -0 $NCPID > /dev/null 2>&1; then + fail "webhook not called, server still running" +fi +# Move forward +echo "$TESTCASE 2" > "$REPO"/file +git -C "$REPO" commit -qam "$TESTCASE 2" +# return a failure to ensure that we try again +{ (echo -e "HTTP/1.1 500 Internal Server Error\r\n" | nc -q1 -l $NCPORT > /dev/null) &} +NCPID=$! +sleep 3 +if kill -0 $NCPID > /dev/null 2>&1; then + fail "2 webhook not called, server still running" +fi +# Now return 200, ensure that it gets called +{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &} +NCPID=$! +sleep 3 +if kill -0 $NCPID > /dev/null 2>&1; then + fail "3 webhook not called, server still running" +fi +# Wrap up +remove_sync_container +wait +pass + echo "cleaning up $DIR" rm -rf "$DIR" From b2677cc434e1fb49be97f1f072d3b223cda2d862 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Wed, 23 Jan 2019 11:05:28 -0800 Subject: [PATCH 2/3] Add e2e test for http handler Tests for #135 --- test_e2e.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test_e2e.sh b/test_e2e.sh index a4e91b6..9f8f6aa 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -633,5 +633,39 @@ remove_sync_container wait pass +# Test http handler +testcase "http" +# First sync +echo "$TESTCASE 1" > "$REPO"/file +expected_depth="1" +git -C "$REPO" commit -qam "$TESTCASE 1" +GIT_SYNC \ + --logtostderr \ + --v=5 \ + --repo="$REPO" \ + --depth="$expected_depth" \ + --root="$ROOT" \ + --http-bind=":8888" \ + --http-metrics \ + --http-pprof \ + --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & +sleep 2 +# check that health endpoint is alive +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888) -ne 200 ]] ; then + fail "health endpoint failed" +fi +# check that the metrics endpoint exists +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/metrics) -ne 200 ]] ; then + fail "metrics endpoint failed" +fi +# check that the pprof endpoint exists +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/debug/pprof/) -ne 200 ]] ; then + fail "pprof endpoint failed" +fi +# Wrap up +remove_sync_container +wait +pass + echo "cleaning up $DIR" rm -rf "$DIR" From 5676842f8c70d51084ea4d043d5eec360cc215d0 Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Wed, 23 Jan 2019 12:30:19 -0800 Subject: [PATCH 3/3] Address comments from PR --- test_e2e.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index 9f8f6aa..6601041 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -594,13 +594,11 @@ testcase "webhook" NCPORT=8888 # First sync echo "$TESTCASE 1" > "$REPO"/file -expected_depth="1" git -C "$REPO" commit -qam "$TESTCASE 1" GIT_SYNC \ --logtostderr \ --v=5 \ --repo="$REPO" \ - --depth="$expected_depth" \ --root="$ROOT" \ --webhook-url="http://127.0.0.1:$NCPORT" \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & @@ -635,31 +633,30 @@ pass # Test http handler testcase "http" +BINDPORT=8888 # First sync echo "$TESTCASE 1" > "$REPO"/file -expected_depth="1" git -C "$REPO" commit -qam "$TESTCASE 1" GIT_SYNC \ --logtostderr \ --v=5 \ --repo="$REPO" \ - --depth="$expected_depth" \ --root="$ROOT" \ - --http-bind=":8888" \ + --http-bind=":$BINDPORT" \ --http-metrics \ --http-pprof \ --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & sleep 2 # check that health endpoint is alive -if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888) -ne 200 ]] ; then +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT) -ne 200 ]] ; then fail "health endpoint failed" fi # check that the metrics endpoint exists -if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/metrics) -ne 200 ]] ; then +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT/metrics) -ne 200 ]] ; then fail "metrics endpoint failed" fi # check that the pprof endpoint exists -if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8888/debug/pprof/) -ne 200 ]] ; then +if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT/debug/pprof/) -ne 200 ]] ; then fail "pprof endpoint failed" fi # Wrap up