Fixup cleanliness in tests

Clean up the tests so that data files that we generate don't get dropped
in the root directory of the host, or in a part of ${TMPDIR} that we
won't clean up.  Add tests to exercise "add"'s extracting logic.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2017-03-07 15:54:51 -05:00
parent 3b44a3e3b3
commit 01a148a00b
4 changed files with 75 additions and 32 deletions

View File

@ -2,25 +2,25 @@
load helpers
@test "add-local" {
createrandom ${TMPDIR}/randomfile
createrandom ${TMPDIR}/other-randomfile
@test "add-local-plain" {
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json --image alpine)
root=$(buildah mount --name=$cid)
mkdir $root/subdir $root/other-subdir
# Copy a file to the working directory
buildah config --workingdir=/ --name=$cid
buildah add --name=$cid ${TMPDIR}/randomfile
buildah add --name=$cid ${TESTDIR}/randomfile
# Copy a file to a specific subdirectory
buildah add --name=$cid --dest=/subdir ${TMPDIR}/randomfile
buildah add --name=$cid --dest=/subdir ${TESTDIR}/randomfile
# Copy a file two files to a specific subdirectory
buildah add --name=$cid --dest=/other-subdir ${TMPDIR}/randomfile ${TMPDIR}/other-randomfile
buildah add --name=$cid --dest=/other-subdir ${TESTDIR}/randomfile ${TESTDIR}/other-randomfile
# Copy a file two files to a specific location, created as a subdirectory
buildah add --name=$cid --dest=/notthereyet-subdir ${TMPDIR}/randomfile ${TMPDIR}/other-randomfile
buildah add --name=$cid --dest=/notthereyet-subdir ${TESTDIR}/randomfile ${TESTDIR}/other-randomfile
# Copy a file to a different working directory
buildah config --workingdir=/cwd --name=$cid
buildah add --name=$cid ${TMPDIR}/randomfile
buildah add --name=$cid ${TESTDIR}/randomfile
buildah unmount --name=$cid
buildah commit --signature-policy ${TESTSDIR}/policy.json --name=$cid --output=containers-storage:new-image
buildah delete --name=$cid
@ -28,20 +28,63 @@ load helpers
newcid=$(buildah from --image new-image)
newroot=$(buildah mount --name=$newcid)
test -s $newroot/randomfile
cmp ${TMPDIR}/randomfile $newroot/randomfile
cmp ${TESTDIR}/randomfile $newroot/randomfile
test -s $newroot/subdir/randomfile
cmp ${TMPDIR}/randomfile $newroot/subdir/randomfile
cmp ${TESTDIR}/randomfile $newroot/subdir/randomfile
test -s $newroot/other-subdir/randomfile
cmp ${TMPDIR}/randomfile $newroot/other-subdir/randomfile
cmp ${TESTDIR}/randomfile $newroot/other-subdir/randomfile
test -s $newroot/other-subdir/other-randomfile
cmp ${TMPDIR}/other-randomfile $newroot/other-subdir/other-randomfile
cmp ${TESTDIR}/other-randomfile $newroot/other-subdir/other-randomfile
test -d $newroot/notthereyet-subdir
test -s $newroot/notthereyet-subdir/randomfile
cmp ${TMPDIR}/randomfile $newroot/notthereyet-subdir/randomfile
cmp ${TESTDIR}/randomfile $newroot/notthereyet-subdir/randomfile
test -s $newroot/notthereyet-subdir/other-randomfile
cmp ${TMPDIR}/other-randomfile $newroot/notthereyet-subdir/other-randomfile
cmp ${TESTDIR}/other-randomfile $newroot/notthereyet-subdir/other-randomfile
test -d $newroot/cwd
test -s $newroot/cwd/randomfile
cmp ${TMPDIR}/randomfile $newroot/cwd/randomfile
cmp ${TESTDIR}/randomfile $newroot/cwd/randomfile
buildah delete --name=$newcid
}
@test "add-local-archive" {
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json --image alpine)
root=$(buildah mount --name=$cid)
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/random2
tar -c -C ${TESTDIR} -f ${TESTDIR}/tarball1.tar random1 random2
mkdir ${TESTDIR}/tarball2
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball2/tarball2.random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball2/tarball2.random2
tar -c -C ${TESTDIR} -z -f ${TESTDIR}/tarball2.tar.gz tarball2
mkdir ${TESTDIR}/tarball3
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball3/tarball3.random1
dd if=/dev/urandom bs=1024 count=4 of=${TESTDIR}/tarball3/tarball3.random2
tar -c -C ${TESTDIR} -j -f ${TESTDIR}/tarball3.tar.bz2 tarball3
# Add the files to the working directory, which should extract them all.
buildah config --workingdir=/ --name=$cid
buildah add --name=$cid ${TESTDIR}/tarball1.tar
buildah add --name=$cid ${TESTDIR}/tarball2.tar.gz
buildah add --name=$cid ${TESTDIR}/tarball3.tar.bz2
buildah unmount --name=$cid
buildah commit --signature-policy ${TESTSDIR}/policy.json --name=$cid --output=containers-storage:new-image
buildah delete --name=$cid
newcid=$(buildah from --image new-image)
newroot=$(buildah mount --name=$newcid)
test -s $newroot/random1
cmp ${TESTDIR}/random1 $newroot/random1
test -s $newroot/random2
cmp ${TESTDIR}/random2 $newroot/random2
test -s $newroot/tarball2/tarball2.random1
cmp ${TESTDIR}/tarball2/tarball2.random1 $newroot/tarball2/tarball2.random1
test -s $newroot/tarball2/tarball2.random2
cmp ${TESTDIR}/tarball2/tarball2.random2 $newroot/tarball2/tarball2.random2
test -s $newroot/tarball3/tarball3.random1
cmp ${TESTDIR}/tarball3/tarball3.random1 $newroot/tarball3/tarball3.random1
test -s $newroot/tarball3/tarball3.random2
cmp ${TESTDIR}/tarball3/tarball3.random2 $newroot/tarball3/tarball3.random2
buildah delete --name=$newcid
}

View File

@ -15,12 +15,12 @@ load helpers
}
@test "commit" {
createrandom ${TMPDIR}/randomfile
createrandom ${TMPDIR}/other-randomfile
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json --image alpine)
root=$(buildah mount --name=$cid)
cp ${TMPDIR}/randomfile $root/randomfile
cp ${TESTDIR}/randomfile $root/randomfile
buildah unmount --name=$cid
buildah commit --signature-policy ${TESTSDIR}/policy.json --name=$cid --output=containers-storage:new-image
buildah delete --name=$cid
@ -28,8 +28,8 @@ load helpers
newcid=$(buildah from --image new-image)
newroot=$(buildah mount --name=$newcid)
test -s $newroot/randomfile
cmp ${TMPDIR}/randomfile $newroot/randomfile
cp ${TMPDIR}/other-randomfile $newroot/other-randomfile
cmp ${TESTDIR}/randomfile $newroot/randomfile
cp ${TESTDIR}/other-randomfile $newroot/other-randomfile
buildah commit --signature-policy ${TESTSDIR}/policy.json --name=$newcid --output=containers-storage:other-new-image
buildah unmount --name=$newcid
buildah delete --name=$newcid
@ -37,8 +37,8 @@ load helpers
othernewcid=$(buildah from --image other-new-image)
othernewroot=$(buildah mount --name=$othernewcid)
test -s $othernewroot/randomfile
cmp ${TMPDIR}/randomfile $othernewroot/randomfile
cmp ${TESTDIR}/randomfile $othernewroot/randomfile
test -s $othernewroot/other-randomfile
cmp ${TMPDIR}/other-randomfile $othernewroot/other-randomfile
cmp ${TESTDIR}/other-randomfile $othernewroot/other-randomfile
buildah delete --name=$othernewcid
}

View File

@ -3,13 +3,13 @@
load helpers
@test "copy-local-plain" {
createrandom ${TMPDIR}/randomfile
createrandom ${TMPDIR}/other-randomfile
createrandom ${TESTDIR}/randomfile
createrandom ${TESTDIR}/other-randomfile
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json --image alpine)
root=$(buildah mount --name=$cid)
buildah config --name=$cid --workingdir /
buildah copy --name=$cid ${TMPDIR}/randomfile
buildah copy --name=$cid ${TESTDIR}/randomfile
buildah unmount --name=$cid
buildah commit --signature-policy ${TESTSDIR}/policy.json --name=$cid --output=containers-storage:new-image
buildah delete --name=$cid
@ -17,6 +17,6 @@ load helpers
newcid=$(buildah from --image new-image)
newroot=$(buildah mount --name=$newcid)
test -s $newroot/randomfile
cmp ${TMPDIR}/randomfile $newroot/randomfile
cmp ${TESTDIR}/randomfile $newroot/randomfile
buildah delete --name=$newcid
}

View File

@ -5,14 +5,14 @@ TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
function setup() {
suffix=$(dd if=/dev/urandom bs=12 count=1 status=none | base64)
TOPDIR=${BATS_TMPDIR}/${suffix}
rm -fr ${TOPDIR}
mkdir -p ${TOPDIR}/{root,runroot}
REPO=${TOPDIR}/root
TESTDIR=${BATS_TMPDIR}/${suffix}
rm -fr ${TESTDIR}
mkdir -p ${TESTDIR}/{root,runroot}
REPO=${TESTDIR}/root
}
function teardown() {
rm -fr ${TOPDIR}
rm -fr ${TESTDIR}
}
function createrandom() {
@ -20,5 +20,5 @@ function createrandom() {
}
function buildah() {
${BUILDAH_BINARY} --debug --root ${TOPDIR}/root --runroot ${TOPDIR}/runroot --storage-driver vfs "$@"
${BUILDAH_BINARY} --debug --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver vfs "$@"
}