2017-03-07 07:11:40 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
BUILDAH_BINARY=${BUILDAH_BINARY:-$(dirname ${BASH_SOURCE})/../buildah}
|
|
|
|
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
|
2017-06-17 02:21:43 +08:00
|
|
|
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
|
2017-03-07 07:11:40 +08:00
|
|
|
|
|
|
|
function setup() {
|
2017-03-08 05:02:12 +08:00
|
|
|
suffix=$(dd if=/dev/urandom bs=12 count=1 status=none | base64 | tr +/ _.)
|
|
|
|
TESTDIR=${BATS_TMPDIR}/tmp.${suffix}
|
2017-03-08 04:54:51 +08:00
|
|
|
rm -fr ${TESTDIR}
|
|
|
|
mkdir -p ${TESTDIR}/{root,runroot}
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
|
|
|
|
2017-05-23 00:08:20 +08:00
|
|
|
function buildimgtype() {
|
|
|
|
go build -tags "$(${TESTSDIR}/../btrfs_tag.sh; ${TESTSDIR}/../libdm_tag.sh)" -o imgtype ${TESTSDIR}/imgtype.go
|
|
|
|
}
|
|
|
|
|
2017-03-28 15:01:59 +08:00
|
|
|
function starthttpd() {
|
2017-03-30 03:50:32 +08:00
|
|
|
pushd ${2:-${TESTDIR}} > /dev/null
|
2017-03-28 15:01:59 +08:00
|
|
|
cp ${TESTSDIR}/serve.go .
|
|
|
|
go build serve.go
|
|
|
|
HTTP_SERVER_PORT=$((RANDOM+32768))
|
|
|
|
./serve ${HTTP_SERVER_PORT} ${1:-${BATS_TMPDIR}} &
|
|
|
|
HTTP_SERVER_PID=$!
|
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function stophttpd() {
|
|
|
|
if test -n "$HTTP_SERVER_PID" ; then
|
|
|
|
kill -HUP ${HTTP_SERVER_PID}
|
|
|
|
unset HTTP_SERVER_PID
|
|
|
|
unset HTTP_SERVER_PORT
|
|
|
|
fi
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:11:40 +08:00
|
|
|
function teardown() {
|
2017-03-28 15:01:59 +08:00
|
|
|
stophttpd
|
2017-03-08 04:54:51 +08:00
|
|
|
rm -fr ${TESTDIR}
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function createrandom() {
|
|
|
|
dd if=/dev/urandom bs=1 count=${2:-256} of=${1:-${BATS_TMPDIR}/randomfile} status=none
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildah() {
|
2017-06-17 02:21:43 +08:00
|
|
|
${BUILDAH_BINARY} --debug --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@"
|
2017-03-07 07:11:40 +08:00
|
|
|
}
|
2017-05-23 00:08:20 +08:00
|
|
|
|
|
|
|
function imgtype() {
|
2017-06-17 02:21:43 +08:00
|
|
|
./imgtype -root ${TESTDIR}/root -runroot ${TESTDIR}/runroot -storage-driver ${STORAGE_DRIVER} "$@"
|
2017-05-23 00:08:20 +08:00
|
|
|
}
|