Merge pull request #332 from thockin/v4-e2e-use-docker-nc
Use docker to run helper servers in e2e
This commit is contained in:
commit
14b9f07f58
1
Makefile
1
Makefile
|
|
@ -181,6 +181,7 @@ test: $(BUILD_DIRS)
|
||||||
|
|
||||||
test-tools:
|
test-tools:
|
||||||
@docker build -t $(REGISTRY)/test/test-sshd _test_tools/sshd
|
@docker build -t $(REGISTRY)/test/test-sshd _test_tools/sshd
|
||||||
|
@docker build -t $(REGISTRY)/test/test-ncsvr _test_tools/ncsvr
|
||||||
|
|
||||||
# Help set up multi-arch build tools. This assumes you have the tools
|
# Help set up multi-arch build tools. This assumes you have the tools
|
||||||
# installed. If you already have a buildx builder available, you don't need
|
# installed. If you already have a buildx builder available, you don't need
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Stolen from https://github.com/linuxkit/linuxkit/tree/master/pkg/sshd/
|
||||||
|
|
||||||
|
FROM alpine AS base
|
||||||
|
|
||||||
|
RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
|
||||||
|
RUN apk add --no-cache --initdb -p /out \
|
||||||
|
alpine-baselayout \
|
||||||
|
apk-tools \
|
||||||
|
busybox \
|
||||||
|
util-linux \
|
||||||
|
netcat-openbsd \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
###############
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
|
||||||
|
ENTRYPOINT []
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
COPY --from=base /out/ /
|
||||||
|
|
||||||
|
COPY ncsvr.sh /
|
||||||
|
|
||||||
|
ENTRYPOINT ["/ncsvr.sh"]
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
# A simple server for tests
|
||||||
|
|
||||||
|
DO NOT USE THIS FOR ANYTHING BUT TESTING!!!
|
||||||
|
|
||||||
|
## How to use it
|
||||||
|
|
||||||
|
Build yourself a test image. We use example.com so you can't accidentally push
|
||||||
|
it.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker build -t example.com/test/test-ncvsr .
|
||||||
|
...lots of output...
|
||||||
|
Successfully tagged example.com/test/test-ncsvr:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Run it.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run -d example.com/test/test-ncsvr 9376 "echo hello"
|
||||||
|
6d05b4111b03c66907031e3cd7587763f0e4fab6c50fac33c4a8284732b448ae
|
||||||
|
```
|
||||||
|
|
||||||
|
Find your IP.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker inspect 6d05b4111b03c66907031e3cd7587763f0e4fab6c50fac33c4a8284732b448ae | jq -r .[0].NetworkSettings.IPAddress
|
||||||
|
192.168.1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
Connect to it.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ echo "" | nc 192.168.9.2 9376
|
||||||
|
hello
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to know how many times it was accessed, mount a file on
|
||||||
|
/var/log/hits. This will log one line per hit.
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -z "$1" -o -z "$2" ]; then
|
||||||
|
echo "usage: $0 <port> <shell-command>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
sh -c "$2" | nc -l -p "$1" -N -w0 >/dev/null
|
||||||
|
date >> /var/log/hits
|
||||||
|
done
|
||||||
243
test_e2e.sh
243
test_e2e.sh
|
|
@ -52,12 +52,31 @@ function assert_file_eq() {
|
||||||
fail "file $1 does not contain '$2': $(cat $1)"
|
fail "file $1 does not contain '$2': $(cat $1)"
|
||||||
}
|
}
|
||||||
|
|
||||||
NCPORT=8888
|
# Helper: run a docker container.
|
||||||
function freencport() {
|
function docker_run() {
|
||||||
while :; do
|
docker run \
|
||||||
NCPORT=$((RANDOM+2000))
|
-d \
|
||||||
ss -lpn | grep -q ":$NCPORT " || break
|
--rm \
|
||||||
done
|
--label git-sync-e2e="$RUNID" \
|
||||||
|
"$@"
|
||||||
|
sleep 2 # wait for it to come up
|
||||||
|
}
|
||||||
|
|
||||||
|
# Helper: get the IP of a docker container.
|
||||||
|
function docker_ip() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "usage: $0 <id>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
docker inspect "$1" | jq -r .[0].NetworkSettings.IPAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
function docker_kill() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "usage: $0 <id>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
docker kill "$1" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# #####################
|
# #####################
|
||||||
|
|
@ -78,13 +97,15 @@ if [[ -z "$DIR" ]]; then
|
||||||
echo "Failed to make a temp dir"
|
echo "Failed to make a temp dir"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo
|
||||||
echo "test root is $DIR"
|
echo "test root is $DIR"
|
||||||
|
echo
|
||||||
|
|
||||||
REPO="$DIR/repo"
|
REPO="$DIR/repo"
|
||||||
function init_repo() {
|
function init_repo() {
|
||||||
rm -rf "$REPO"
|
rm -rf "$REPO"
|
||||||
mkdir -p "$REPO"
|
mkdir -p "$REPO"
|
||||||
git -C "$REPO" init -q -b master
|
git -C "$REPO" init -q -b e2e-branch
|
||||||
touch "$REPO"/file
|
touch "$REPO"/file
|
||||||
git -C "$REPO" add file
|
git -C "$REPO" add file
|
||||||
git -C "$REPO" commit -aqm "init file"
|
git -C "$REPO" commit -aqm "init file"
|
||||||
|
|
@ -104,7 +125,8 @@ cat "$DOT_SSH/id_test.pub" > "$DOT_SSH/authorized_keys"
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "The directory $DIR was not removed as it contains"\
|
echo
|
||||||
|
echo "the directory $DIR was not removed as it contains"\
|
||||||
"log files useful for debugging"
|
"log files useful for debugging"
|
||||||
fi
|
fi
|
||||||
remove_containers
|
remove_containers
|
||||||
|
|
@ -153,7 +175,7 @@ rm -rf "$ROOT" # remove the root to test
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -173,7 +195,7 @@ git -C "$REPO" commit -qam "$TESTCASE"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -193,7 +215,7 @@ git -C "$REPO" commit -qam "$TESTCASE"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="../../../../../$ROOT/../../../../../../$ROOT" \
|
--root="../../../../../$ROOT/../../../../../../$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -214,7 +236,7 @@ ln -s "$ROOT" "$DIR/rootlink" # symlink to test
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$DIR/rootlink" \
|
--root="$DIR/rootlink" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -226,12 +248,13 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Test default syncing
|
# Test default syncing (master)
|
||||||
##############################################
|
##############################################
|
||||||
testcase "default-sync"
|
testcase "default-sync-master"
|
||||||
# First sync
|
# First sync
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
|
git -C "$REPO" checkout -q -b master
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
|
@ -268,7 +291,7 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -302,7 +325,7 @@ BRANCH="$TESTCASE"--BRANCH
|
||||||
git -C "$REPO" checkout -q -b "$BRANCH"
|
git -C "$REPO" checkout -q -b "$BRANCH"
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
git -C "$REPO" checkout -q master
|
git -C "$REPO" checkout -q e2e-branch
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
|
@ -318,7 +341,7 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
||||||
git -C "$REPO" checkout -q "$BRANCH"
|
git -C "$REPO" checkout -q "$BRANCH"
|
||||||
echo "$TESTCASE 2" > "$REPO"/file
|
echo "$TESTCASE 2" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 2"
|
git -C "$REPO" commit -qam "$TESTCASE 2"
|
||||||
git -C "$REPO" checkout -q master
|
git -C "$REPO" checkout -q e2e-branch
|
||||||
sleep 3
|
sleep 3
|
||||||
assert_link_exists "$ROOT"/link
|
assert_link_exists "$ROOT"/link
|
||||||
assert_file_exists "$ROOT"/link/file
|
assert_file_exists "$ROOT"/link/file
|
||||||
|
|
@ -326,7 +349,7 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 2"
|
||||||
# Move the branch backward
|
# Move the branch backward
|
||||||
git -C "$REPO" checkout -q "$BRANCH"
|
git -C "$REPO" checkout -q "$BRANCH"
|
||||||
git -C "$REPO" reset -q --hard HEAD^
|
git -C "$REPO" reset -q --hard HEAD^
|
||||||
git -C "$REPO" checkout -q master
|
git -C "$REPO" checkout -q e2e-branch
|
||||||
sleep 3
|
sleep 3
|
||||||
assert_link_exists "$ROOT"/link
|
assert_link_exists "$ROOT"/link
|
||||||
assert_file_exists "$ROOT"/link/file
|
assert_file_exists "$ROOT"/link/file
|
||||||
|
|
@ -346,6 +369,7 @@ git -C "$REPO" tag -f "$TAG" >/dev/null
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--rev="$TAG" \
|
--rev="$TAG" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -391,6 +415,7 @@ git -C "$REPO" tag -af "$TAG" -m "$TESTCASE 1" >/dev/null
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--rev="$TAG" \
|
--rev="$TAG" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -435,6 +460,7 @@ REV=$(git -C "$REPO" rev-list -n1 HEAD)
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--rev="$REV" \
|
--rev="$REV" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -470,6 +496,7 @@ REV=$(git -C "$REPO" rev-list -n1 HEAD)
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--rev="$REV" \
|
--rev="$REV" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -490,6 +517,7 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1
|
> "$DIR"/log."$TESTCASE" 2>&1
|
||||||
|
|
@ -502,6 +530,7 @@ rm -f "$ROOT"/link
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1
|
> "$DIR"/log."$TESTCASE" 2>&1
|
||||||
|
|
@ -523,6 +552,7 @@ GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--sync-timeout=1s \
|
--sync-timeout=1s \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 || true
|
> "$DIR"/log."$TESTCASE" 2>&1 || true
|
||||||
|
|
@ -534,6 +564,7 @@ GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--sync-timeout=16s \
|
--sync-timeout=16s \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 &
|
> "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
|
|
@ -562,6 +593,7 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--depth="$expected_depth" \
|
--depth="$expected_depth" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -611,7 +643,7 @@ GIT_SYNC \
|
||||||
--password="wrong" \
|
--password="wrong" \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -625,7 +657,7 @@ GIT_SYNC \
|
||||||
--password="my-password" \
|
--password="my-password" \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -641,46 +673,42 @@ pass
|
||||||
##############################################
|
##############################################
|
||||||
testcase "askpass_url"
|
testcase "askpass_url"
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
freencport
|
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
# run the askpass_url service with wrong password
|
# run the askpass_url service with wrong password
|
||||||
{ (
|
CTR=$(docker_run \
|
||||||
for i in 1 2; do
|
e2e/test/test-ncsvr \
|
||||||
echo -e 'HTTP/1.1 200 OK\r\n\r\nusername=my-username\npassword=wrong' \
|
80 'echo -e "HTTP/1.1 200 OK\r\n\r\nusername=my-username\npassword=wrong"')
|
||||||
| nc -N -l $NCPORT > /dev/null;
|
IP=$(docker_ip "$CTR")
|
||||||
done
|
|
||||||
) &
|
|
||||||
}
|
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--git="$ASKPASS_GIT" \
|
--git="$ASKPASS_GIT" \
|
||||||
--askpass-url="http://localhost:$NCPORT/git_askpass" \
|
--askpass-url="http://$IP/git_askpass" \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 || true
|
> "$DIR"/log."$TESTCASE" 2>&1 || true
|
||||||
|
docker_kill "$CTR"
|
||||||
# check for failure
|
# check for failure
|
||||||
assert_file_absent "$ROOT"/link/file
|
assert_file_absent "$ROOT"/link/file
|
||||||
|
|
||||||
# run with askpass_url service with correct password
|
# run with askpass_url service with correct password
|
||||||
{ (
|
CTR=$(docker_run \
|
||||||
for i in 1 2; do
|
e2e/test/test-ncsvr \
|
||||||
echo -e 'HTTP/1.1 200 OK\r\n\r\nusername=my-username\npassword=my-password' \
|
80 'echo -e "HTTP/1.1 200 OK\r\n\r\nusername=my-username\npassword=my-password"')
|
||||||
| nc -N -l $NCPORT > /dev/null;
|
IP=$(docker_ip "$CTR")
|
||||||
done
|
|
||||||
) &
|
|
||||||
}
|
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--git="$ASKPASS_GIT" \
|
--git="$ASKPASS_GIT" \
|
||||||
--askpass-url="http://localhost:$NCPORT/git_askpass" \
|
--askpass-url="http://$IP/git_askpass" \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1
|
>> "$DIR"/log."$TESTCASE" 2>&1
|
||||||
|
docker_kill "$CTR"
|
||||||
assert_link_exists "$ROOT"/link
|
assert_link_exists "$ROOT"/link
|
||||||
assert_file_exists "$ROOT"/link/file
|
assert_file_exists "$ROOT"/link/file
|
||||||
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
assert_file_eq "$ROOT"/link/file "$TESTCASE 1"
|
||||||
|
|
@ -697,6 +725,7 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
--sync-hook-command="$SYNC_HOOK_COMMAND" \
|
--sync-hook-command="$SYNC_HOOK_COMMAND" \
|
||||||
|
|
@ -723,42 +752,88 @@ pass
|
||||||
# Test webhook success
|
# Test webhook success
|
||||||
##############################################
|
##############################################
|
||||||
testcase "webhook-success"
|
testcase "webhook-success"
|
||||||
freencport
|
HITLOG="$DIR/hitlog.$TESTCASE"
|
||||||
# First sync
|
# First sync
|
||||||
|
cat /dev/null > "$HITLOG"
|
||||||
|
CTR=$(docker_run \
|
||||||
|
-v "$HITLOG":/var/log/hits \
|
||||||
|
e2e/test/test-ncsvr \
|
||||||
|
80 'echo -e "HTTP/1.1 200 OK\r\n"')
|
||||||
|
IP=$(docker_ip "$CTR")
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--webhook-url="http://127.0.0.1:$NCPORT" \
|
--webhook-url="http://$IP" \
|
||||||
--webhook-success-status=200 \
|
--webhook-success-status=200 \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 &
|
> "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
# check that basic call works
|
# check that basic call works
|
||||||
{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
|
sleep 2
|
||||||
NCPID=$!
|
HITS=$(cat "$HITLOG" | wc -l)
|
||||||
sleep 3
|
if [ "$HITS" -lt 1 ]; then
|
||||||
if kill -0 $NCPID > /dev/null 2>&1; then
|
fail "webhook 1 called $HITS times"
|
||||||
fail "webhook 1 not called, server still running"
|
|
||||||
fi
|
fi
|
||||||
# Move forward
|
# Move forward
|
||||||
|
cat /dev/null > "$HITLOG"
|
||||||
echo "$TESTCASE 2" > "$REPO"/file
|
echo "$TESTCASE 2" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 2"
|
git -C "$REPO" commit -qam "$TESTCASE 2"
|
||||||
# return a failure to ensure that we try again
|
# check that another call works
|
||||||
{ (echo -e "HTTP/1.1 500 Internal Server Error\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
|
sleep 2
|
||||||
NCPID=$!
|
HITS=$(cat "$HITLOG" | wc -l)
|
||||||
sleep 3
|
if [ "$HITS" -lt 1 ]; then
|
||||||
if kill -0 $NCPID > /dev/null 2>&1; then
|
fail "webhook 2 called $HITS times"
|
||||||
fail "webhook 2 not called, server still running"
|
|
||||||
fi
|
fi
|
||||||
|
docker_kill "$CTR"
|
||||||
|
# Wrap up
|
||||||
|
pass
|
||||||
|
|
||||||
|
##############################################
|
||||||
|
# Test webhook fail-retry
|
||||||
|
##############################################
|
||||||
|
testcase "webhook-fail-retry"
|
||||||
|
HITLOG="$DIR/hitlog.$TESTCASE"
|
||||||
|
# First sync - return a failure to ensure that we try again
|
||||||
|
cat /dev/null > "$HITLOG"
|
||||||
|
CTR=$(docker_run \
|
||||||
|
-v "$HITLOG":/var/log/hits \
|
||||||
|
e2e/test/test-ncsvr \
|
||||||
|
80 'echo -e "HTTP/1.1 500 Internal Server Error\r\n"')
|
||||||
|
IP=$(docker_ip "$CTR")
|
||||||
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
|
GIT_SYNC \
|
||||||
|
--period=100ms \
|
||||||
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
|
--root="$ROOT" \
|
||||||
|
--webhook-url="http://$IP" \
|
||||||
|
--webhook-success-status=200 \
|
||||||
|
--link="link" \
|
||||||
|
> "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
|
# Check that webhook was called
|
||||||
|
sleep 2
|
||||||
|
HITS=$(cat "$HITLOG" | wc -l)
|
||||||
|
if [ "$HITS" -lt 1 ]; then
|
||||||
|
fail "webhook 1 called $HITS times"
|
||||||
|
fi
|
||||||
|
docker_kill "$CTR"
|
||||||
# Now return 200, ensure that it gets called
|
# Now return 200, ensure that it gets called
|
||||||
{ (echo -e "HTTP/1.1 200 OK\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
|
cat /dev/null > "$HITLOG"
|
||||||
NCPID=$!
|
CTR=$(docker_run \
|
||||||
sleep 3
|
--ip="$IP" \
|
||||||
if kill -0 $NCPID > /dev/null 2>&1; then
|
-v "$HITLOG":/var/log/hits \
|
||||||
fail "webhook 3 not called, server still running"
|
e2e/test/test-ncsvr \
|
||||||
|
80 'echo -e "HTTP/1.1 200 OK\r\n"')
|
||||||
|
sleep 2
|
||||||
|
HITS=$(cat "$HITLOG" | wc -l)
|
||||||
|
if [ "$HITS" -lt 1 ]; then
|
||||||
|
fail "webhook 2 called $HITS times"
|
||||||
fi
|
fi
|
||||||
|
docker_kill "$CTR"
|
||||||
# Wrap up
|
# Wrap up
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -766,25 +841,33 @@ pass
|
||||||
# Test webhook fire-and-forget
|
# Test webhook fire-and-forget
|
||||||
##############################################
|
##############################################
|
||||||
testcase "webhook-fire-and-forget"
|
testcase "webhook-fire-and-forget"
|
||||||
freencport
|
HITLOG="$DIR/hitlog.$TESTCASE"
|
||||||
|
# First sync
|
||||||
|
cat /dev/null > "$HITLOG"
|
||||||
|
CTR=$(docker_run \
|
||||||
|
-v "$HITLOG":/var/log/hits \
|
||||||
|
e2e/test/test-ncsvr \
|
||||||
|
80 'echo -e "HTTP/1.1 404 Not Found\r\n"')
|
||||||
|
IP=$(docker_ip "$CTR")
|
||||||
# First sync
|
# First sync
|
||||||
echo "$TESTCASE 1" > "$REPO"/file
|
echo "$TESTCASE 1" > "$REPO"/file
|
||||||
git -C "$REPO" commit -qam "$TESTCASE 1"
|
git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--webhook-url="http://127.0.0.1:$NCPORT" \
|
--webhook-url="http://$IP" \
|
||||||
--webhook-success-status=-1 \
|
--webhook-success-status=-1 \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 &
|
> "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
# check that basic call works
|
# check that basic call works
|
||||||
{ (echo -e "HTTP/1.1 404 Not Found\r\n" | nc -q1 -l $NCPORT > /dev/null) &}
|
sleep 2
|
||||||
NCPID=$!
|
HITS=$(cat "$HITLOG" | wc -l)
|
||||||
sleep 3
|
if [ "$HITS" -lt 1 ]; then
|
||||||
if kill -0 $NCPID > /dev/null 2>&1; then
|
fail "webhook called $HITS times"
|
||||||
fail "webhook 1 not called, server still running"
|
|
||||||
fi
|
fi
|
||||||
|
docker_kill "$CTR"
|
||||||
# Wrap up
|
# Wrap up
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
@ -800,6 +883,7 @@ GIT_SYNC \
|
||||||
--git="$SLOW_GIT" \
|
--git="$SLOW_GIT" \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--http-bind=":$BINDPORT" \
|
--http-bind=":$BINDPORT" \
|
||||||
--http-metrics \
|
--http-metrics \
|
||||||
|
|
@ -840,7 +924,7 @@ SUBMODULE_REPO_NAME="sub"
|
||||||
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
||||||
mkdir "$SUBMODULE"
|
mkdir "$SUBMODULE"
|
||||||
|
|
||||||
git -C "$SUBMODULE" init -q -b master
|
git -C "$SUBMODULE" init -q -b e2e-branch
|
||||||
echo "submodule" > "$SUBMODULE"/submodule
|
echo "submodule" > "$SUBMODULE"/submodule
|
||||||
git -C "$SUBMODULE" add submodule
|
git -C "$SUBMODULE" add submodule
|
||||||
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
||||||
|
|
@ -850,7 +934,7 @@ NESTED_SUBMODULE_REPO_NAME="nested-sub"
|
||||||
NESTED_SUBMODULE="$DIR/$NESTED_SUBMODULE_REPO_NAME"
|
NESTED_SUBMODULE="$DIR/$NESTED_SUBMODULE_REPO_NAME"
|
||||||
mkdir "$NESTED_SUBMODULE"
|
mkdir "$NESTED_SUBMODULE"
|
||||||
|
|
||||||
git -C "$NESTED_SUBMODULE" init -q -b master
|
git -C "$NESTED_SUBMODULE" init -q -b e2e-branch
|
||||||
echo "nested-submodule" > "$NESTED_SUBMODULE"/nested-submodule
|
echo "nested-submodule" > "$NESTED_SUBMODULE"/nested-submodule
|
||||||
git -C "$NESTED_SUBMODULE" add nested-submodule
|
git -C "$NESTED_SUBMODULE" add nested-submodule
|
||||||
git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file"
|
git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file"
|
||||||
|
|
@ -861,6 +945,7 @@ git -C "$REPO" commit -aqm "add submodule"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
> "$DIR"/log."$TESTCASE" 2>&1 &
|
> "$DIR"/log."$TESTCASE" 2>&1 &
|
||||||
|
|
@ -935,7 +1020,7 @@ SUBMODULE_REPO_NAME="sub"
|
||||||
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
||||||
mkdir "$SUBMODULE"
|
mkdir "$SUBMODULE"
|
||||||
|
|
||||||
git -C "$SUBMODULE" init -q -b master
|
git -C "$SUBMODULE" init -q -b e2e-branch
|
||||||
|
|
||||||
# First sync
|
# First sync
|
||||||
expected_depth="1"
|
expected_depth="1"
|
||||||
|
|
@ -948,6 +1033,7 @@ git -C "$REPO" commit -qam "$TESTCASE 1"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--depth="$expected_depth" \
|
--depth="$expected_depth" \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -1011,7 +1097,7 @@ SUBMODULE_REPO_NAME="sub"
|
||||||
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
||||||
mkdir "$SUBMODULE"
|
mkdir "$SUBMODULE"
|
||||||
|
|
||||||
git -C "$SUBMODULE" init -q -b master
|
git -C "$SUBMODULE" init -q -b e2e-branch
|
||||||
echo "submodule" > "$SUBMODULE"/submodule
|
echo "submodule" > "$SUBMODULE"/submodule
|
||||||
git -C "$SUBMODULE" add submodule
|
git -C "$SUBMODULE" add submodule
|
||||||
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
||||||
|
|
@ -1023,6 +1109,7 @@ git -C "$REPO" commit -aqm "add submodule"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
--submodules=off \
|
--submodules=off \
|
||||||
|
|
@ -1042,7 +1129,7 @@ SUBMODULE_REPO_NAME="sub"
|
||||||
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
SUBMODULE="$DIR/$SUBMODULE_REPO_NAME"
|
||||||
mkdir "$SUBMODULE"
|
mkdir "$SUBMODULE"
|
||||||
|
|
||||||
git -C "$SUBMODULE" init -q -b master
|
git -C "$SUBMODULE" init -q -b e2e-branch
|
||||||
echo "submodule" > "$SUBMODULE"/submodule
|
echo "submodule" > "$SUBMODULE"/submodule
|
||||||
git -C "$SUBMODULE" add submodule
|
git -C "$SUBMODULE" add submodule
|
||||||
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
git -C "$SUBMODULE" commit -aqm "init submodule file"
|
||||||
|
|
@ -1051,7 +1138,7 @@ NESTED_SUBMODULE_REPO_NAME="nested-sub"
|
||||||
NESTED_SUBMODULE="$DIR/$NESTED_SUBMODULE_REPO_NAME"
|
NESTED_SUBMODULE="$DIR/$NESTED_SUBMODULE_REPO_NAME"
|
||||||
mkdir "$NESTED_SUBMODULE"
|
mkdir "$NESTED_SUBMODULE"
|
||||||
|
|
||||||
git -C "$NESTED_SUBMODULE" init -q -b master
|
git -C "$NESTED_SUBMODULE" init -q -b e2e-branch
|
||||||
echo "nested-submodule" > "$NESTED_SUBMODULE"/nested-submodule
|
echo "nested-submodule" > "$NESTED_SUBMODULE"/nested-submodule
|
||||||
git -C "$NESTED_SUBMODULE" add nested-submodule
|
git -C "$NESTED_SUBMODULE" add nested-submodule
|
||||||
git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file"
|
git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file"
|
||||||
|
|
@ -1065,6 +1152,7 @@ git -C "$REPO" commit -aqm "add submodule"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--period=100ms \
|
--period=100ms \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
--branch=e2e-branch \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
--submodules=shallow \
|
--submodules=shallow \
|
||||||
|
|
@ -1084,20 +1172,16 @@ pass
|
||||||
testcase "ssh"
|
testcase "ssh"
|
||||||
echo "$TESTCASE" > "$REPO"/file
|
echo "$TESTCASE" > "$REPO"/file
|
||||||
# Run a git-over-SSH server
|
# Run a git-over-SSH server
|
||||||
CTR=$(docker run \
|
CTR=$(docker_run \
|
||||||
-d \
|
|
||||||
--rm \
|
|
||||||
--label git-sync-e2e="$RUNID" \
|
|
||||||
-v "$DOT_SSH":/dot_ssh:ro \
|
-v "$DOT_SSH":/dot_ssh:ro \
|
||||||
-v "$REPO":/src:ro \
|
-v "$REPO":/src:ro \
|
||||||
e2e/test/test-sshd)
|
e2e/test/test-sshd)
|
||||||
sleep 3 # wait for sshd to come up
|
IP=$(docker_ip "$CTR")
|
||||||
IP=$(docker inspect "$CTR" | jq -r .[0].NetworkSettings.IPAddress)
|
|
||||||
git -C "$REPO" commit -qam "$TESTCASE"
|
git -C "$REPO" commit -qam "$TESTCASE"
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="test@$IP:/src" \
|
--repo="test@$IP:/src" \
|
||||||
--branch=master \
|
--branch=e2e-branch \
|
||||||
--rev=HEAD \
|
--rev=HEAD \
|
||||||
--root="$ROOT" \
|
--root="$ROOT" \
|
||||||
--link="link" \
|
--link="link" \
|
||||||
|
|
@ -1110,5 +1194,6 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE"
|
||||||
# Wrap up
|
# Wrap up
|
||||||
pass
|
pass
|
||||||
|
|
||||||
echo "cleaning up $DIR"
|
echo
|
||||||
|
echo "all tests passed: cleaning up $DIR"
|
||||||
rm -rf "$DIR"
|
rm -rf "$DIR"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue