Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bud.bats: use a local git daemon for the git protocol test #3701

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,11 @@ function _test_http() {
skip "no ssh in PATH"
fi
target=giturl-image
# Any repo should do, but this one is small and is FROM: scratch.
gitrepo=git://github.com/projectatomic/nulecule-library
# Any repo would do, but this one is small, is FROM: scratch, and local.
if ! start_git_daemon ; then
skip "error running git daemon"
fi
gitrepo=git://localhost:${GITPORT}/repo
run_buildah build --signature-policy ${TESTSDIR}/policy.json -t ${target} "${gitrepo}"
run_buildah from ${target}
}
Expand Down Expand Up @@ -2282,11 +2285,14 @@ _EOF
}

@test "bud using gitrepo and branch" {
run_buildah build --signature-policy ${TESTSDIR}/policy.json --layers -t gittarget -f tests/bud/shell/Dockerfile git://github.com/containers/buildah#release-1.11-rhel
if ! start_git_daemon ${TESTSDIR}/git-daemon/release-1.11-rhel.tar.gz ; then
skip "error running git daemon"
fi
run_buildah build --signature-policy ${TESTSDIR}/policy.json --layers -t gittarget -f ${TESTSDIR}/bud/shell/Dockerfile git://localhost:${GITPORT}/repo#release-1.11-rhel
}

@test "bud using gitrepo with .git and branch" {
run_buildah build --signature-policy ${TESTSDIR}/policy.json --layers -t gittarget -f tests/bud/shell/Dockerfile https://github.com/containers/buildah.git#release-1.11-rhel
run_buildah build --signature-policy ${TESTSDIR}/policy.json --layers -t gittarget -f ${TESTSDIR}/bud/shell/Dockerfile https://github.com/containers/buildah.git#release-1.11-rhel
}

# Fixes #1906: buildah was not detecting changed tarfile
Expand Down
Binary file added tests/git-daemon/release-1.11-rhel.tar.gz
Binary file not shown.
Binary file added tests/git-daemon/repo.tar.gz
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function teardown(){

function teardown_tests() {
stophttpd
stop_git_daemon

# Workaround for #1991 - buildah + overlayfs leaks mount points.
# Many tests leave behind /var/tmp/.../root/overlay and sub-mounts;
Expand Down Expand Up @@ -497,3 +498,18 @@ function skip_if_no_docker() {
skip "this test needs actual docker, not podman-docker"
fi
}

function start_git_daemon() {
daemondir=${TESTDIR}/git-daemon
mkdir -p ${daemondir}/repo
gzip -dc < ${1:-${TESTSDIR}/git-daemon/repo.tar.gz} | tar x -C ${daemondir}/repo
GITPORT=$(($RANDOM + 32768))
git daemon --detach --pid-file=${TESTDIR}/git-daemon/pid --reuseaddr --port=${GITPORT} --base-path=${daemondir} ${daemondir}
}

function stop_git_daemon() {
if test -s ${TESTDIR}/git-daemon/pid ; then
kill $(cat ${TESTDIR}/git-daemon/pid)
rm -f ${TESTDIR}/git-daemon/pid
fi
}