@@ -89,6 +89,7 @@ function GIT_SYNC() {
89
89
-u $( id -u) :$( id -g) \
90
90
-v " $DIR " :" $DIR " \
91
91
-v " $( pwd) /slow_git.sh" :" /slow_git.sh" \
92
+ --network=" host" \
92
93
--rm \
93
94
e2e/git-sync:$( make -s version) __$( go env GOOS) _$( go env GOARCH) \
94
95
" $@ "
@@ -588,5 +589,80 @@ remove_sync_container
588
589
wait
589
590
pass
590
591
592
+ # Test webhook
593
+ testcase " webhook"
594
+ NCPORT=8888
595
+ # First sync
596
+ echo " $TESTCASE 1" > " $REPO " /file
597
+ git -C " $REPO " commit -qam " $TESTCASE 1"
598
+ GIT_SYNC \
599
+ --logtostderr \
600
+ --v=5 \
601
+ --repo=" $REPO " \
602
+ --root=" $ROOT " \
603
+ --webhook-url=" http://127.0.0.1:$NCPORT " \
604
+ --dest=" link" > " $DIR " /log." $TESTCASE " 2>&1 &
605
+ # check that basic call works
606
+ { (echo -e " HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) & }
607
+ NCPID=$!
608
+ sleep 3
609
+ if kill -0 $NCPID > /dev/null 2>&1 ; then
610
+ fail " webhook not called, server still running"
611
+ fi
612
+ # Move forward
613
+ echo " $TESTCASE 2" > " $REPO " /file
614
+ git -C " $REPO " commit -qam " $TESTCASE 2"
615
+ # return a failure to ensure that we try again
616
+ { (echo -e " HTTP/1.1 500 Internal Server Error\r\n" | nc -q1 -l $NCPORT > /dev/null) & }
617
+ NCPID=$!
618
+ sleep 3
619
+ if kill -0 $NCPID > /dev/null 2>&1 ; then
620
+ fail " 2 webhook not called, server still running"
621
+ fi
622
+ # Now return 200, ensure that it gets called
623
+ { (echo -e " HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) & }
624
+ NCPID=$!
625
+ sleep 3
626
+ if kill -0 $NCPID > /dev/null 2>&1 ; then
627
+ fail " 3 webhook not called, server still running"
628
+ fi
629
+ # Wrap up
630
+ remove_sync_container
631
+ wait
632
+ pass
633
+
634
+ # Test http handler
635
+ testcase " http"
636
+ BINDPORT=8888
637
+ # First sync
638
+ echo " $TESTCASE 1" > " $REPO " /file
639
+ git -C " $REPO " commit -qam " $TESTCASE 1"
640
+ GIT_SYNC \
641
+ --logtostderr \
642
+ --v=5 \
643
+ --repo=" $REPO " \
644
+ --root=" $ROOT " \
645
+ --http-bind=" :$BINDPORT " \
646
+ --http-metrics \
647
+ --http-pprof \
648
+ --dest=" link" > " $DIR " /log." $TESTCASE " 2>&1 &
649
+ sleep 2
650
+ # check that health endpoint is alive
651
+ if [[ $( curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT ) -ne 200 ]] ; then
652
+ fail " health endpoint failed"
653
+ fi
654
+ # check that the metrics endpoint exists
655
+ if [[ $( curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT /metrics) -ne 200 ]] ; then
656
+ fail " metrics endpoint failed"
657
+ fi
658
+ # check that the pprof endpoint exists
659
+ if [[ $( curl --write-out %{http_code} --silent --output /dev/null http://localhost:$BINDPORT /debug/pprof/) -ne 200 ]] ; then
660
+ fail " pprof endpoint failed"
661
+ fi
662
+ # Wrap up
663
+ remove_sync_container
664
+ wait
665
+ pass
666
+
591
667
echo " cleaning up $DIR "
592
668
rm -rf " $DIR "
0 commit comments