tests/e2e.sh
#!/bin/sh
# End-to-end test against a local S3 gateway. Run it with `just e2e`.
# Needs git, aws and versitygw on PATH, and a debug build of the helper.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
trap 'kill "$server" 2>/dev/null; rm -rf "$work"' EXIT
export PATH="$root/target/debug:$PATH"
export AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=testsecret AWS_REGION=us-east-1
export AWS_ENDPOINT_URL=http://127.0.0.1:7070
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null
export GIT_AUTHOR_NAME=test GIT_AUTHOR_EMAIL=test@example.com
export GIT_COMMITTER_NAME=test GIT_COMMITTER_EMAIL=test@example.com
url=s3://e2e/repo
lock='repo/refs/heads/main/LOCK#.lock'
step() { printf '== %s\n' "$1"; }
fail() { printf 'FAIL: %s\n' "$1"; exit 1; }
commit() { echo "$2" >>"$1/file" && git -C "$1" add file && git -C "$1" commit -qm "$2"; }
tip() { git -C "$1" rev-parse HEAD; }
keys() { aws s3 ls --recursive s3://e2e/repo/ | awk '{print $4}'; }
mkdir "$work/data" "$work/meta"
versitygw --port 127.0.0.1:7070 --access test --secret testsecret \
posix --sidecar "$work/meta" "$work/data" >"$work/server.log" 2>&1 &
server=$!
tries=0
until aws s3 mb s3://e2e >/dev/null 2>&1; do
tries=$((tries + 1))
[ "$tries" -lt 50 ] || { cat "$work/server.log"; fail "server did not start"; }
sleep 0.2
done
cd "$work"
step "push, then clone"
git init -q -b main a
commit a one
git -C a remote add origin "$url"
git -C a push -q origin main
git clone -q "$url" b
[ "$(tip a)" = "$(tip b)" ] || fail "clone differs from source"
[ "$(git -C b symbolic-ref HEAD)" = refs/heads/main ] || fail "clone has wrong HEAD"
step "push again, then pull"
commit a two
git -C a push -q origin main
git -C b pull -q
[ "$(tip a)" = "$(tip b)" ] || fail "pull differs from source"
step "push that is not a fast-forward is rejected"
commit b three
git -C b push -q origin main
commit a other
if git -C a push -q origin main 2>/dev/null; then fail "push was accepted"; fi
step "force push"
git -C a push -q --force origin main
[ "$(git ls-remote "$url" refs/heads/main | cut -f1)" = "$(tip a)" ] || fail "remote not updated"
step "push is rejected while the ref is locked"
aws s3api put-object --bucket e2e --key "$lock" >/dev/null
commit a four
if git -C a push -q origin main 2>/dev/null; then fail "push ignored the lock"; fi
aws s3api delete-object --bucket e2e --key "$lock" >/dev/null
git -C a push -q origin main
step "push and delete a second branch"
git -C a push -q origin main:refs/heads/topic/x
git ls-remote "$url" | grep -q refs/heads/topic/x || fail "branch not pushed"
step "clone downloads a commit one time only"
# Break the second bundle. The clone must get the commit from the bundle of main.
echo broken >broken
aws s3api put-object --bucket e2e --body broken \
--key "repo/refs/heads/topic/x/$(tip a).bundle" >/dev/null
git clone -q "$url" c
[ "$(git -C c rev-parse origin/topic/x)" = "$(tip a)" ] || fail "branch missing in clone"
step "delete the second branch"
git -C a push -q origin :refs/heads/topic/x
if git ls-remote "$url" | grep -q topic; then fail "branch not deleted"; fi
step "fetch finds the new bundle when a push replaced the wanted one"
old=$(git -C a rev-parse HEAD~1)
git init -q d
printf 'fetch %s refs/heads/main\n\n' "$old" | GIT_DIR=d/.git git-remote-s3 origin "$url" >/dev/null
git -C d cat-file -e "$old" || fail "commit not fetched"
step "push repairs a ref that has two bundles"
# Put back an old bundle, then make the bundle of the tip the newest one.
tip=$(tip a)
aws s3 cp --quiet "s3://e2e/repo/refs/heads/main/$tip.bundle" tip.bundle
git -C a branch old "$old"
git -C a bundle create -q "$work/old.bundle" old
aws s3 cp --quiet old.bundle "s3://e2e/repo/refs/heads/main/$old.bundle"
sleep 2
aws s3 cp --quiet tip.bundle "s3://e2e/repo/refs/heads/main/$tip.bundle"
[ "$(git ls-remote "$url" refs/heads/main | cut -f1)" = "$tip" ] || fail "wrong tip with two bundles"
commit a five
git -C a push -q origin main
step "credentials come from the AWS CLI when the environment has none"
printf '[default]\naws_access_key_id = test\naws_secret_access_key = testsecret\n' >credentials
printf '[default]\nregion = us-east-1\n' >config
(
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION
export AWS_SHARED_CREDENTIALS_FILE="$work/credentials" AWS_CONFIG_FILE="$work/config"
git ls-remote "$url" | grep -q refs/heads/main
) || fail "no refs with CLI credentials"
step "bucket holds one bundle and HEAD"
want="repo/HEAD
repo/refs/heads/main/$(tip a).bundle"
[ "$(keys)" = "$want" ] || { keys; fail "unexpected keys"; }
echo PASS