diff --git a/tests/add.bats b/tests/add.bats index 7bd03b4eb8b..5785dd3490b 100644 --- a/tests/add.bats +++ b/tests/add.bats @@ -113,13 +113,13 @@ load helpers run_buildah add $cid ${TESTDIR}/distutils.cfg /usr/lib/python3.7/distutils run_buildah run $cid stat -c "%a" /usr/lib/python3.7/distutils root=$(buildah mount $cid) - expect_output --substring "755" + expect_output "644" run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:${imgName} run_buildah rm $cid newcid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${imgName}) run_buildah run $newcid stat -c "%a" /usr/lib/python3.7/distutils - expect_output --substring "755" + expect_output "644" run_buildah rm $newcid } @@ -131,12 +131,12 @@ load helpers run_buildah add $cid ${TESTDIR}/distutils.cfg lib/custom run_buildah run $cid stat -c "%a" lib/custom root=$(buildah mount $cid) - expect_output --substring "755" + expect_output "644" run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:${imgName} run_buildah rm $cid newcid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${imgName}) run_buildah run $newcid stat -c "%a" lib/custom - expect_output --substring "755" + expect_output "644" run_buildah rm $newcid } diff --git a/tests/bud.bats b/tests/bud.bats index f3a7021bdf3..6be4b3a48a4 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -3,12 +3,11 @@ load helpers @test "bud with --dns* flags" { - run buildah bud --log-level=error --dns-search=example.com --dns=223.5.5.5 --dns-option=use-vc --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/dns/Dockerfile ${TESTSDIR}/bud/dns - echo "$output" - [[ "$output" =~ "search example.com" ]] - [[ "$output" =~ "nameserver 223.5.5.5" ]] - [[ "$output" =~ "options use-vc" ]] - [ "$status" -eq 0 ] + run_buildah bud --log-level=error --dns-search=example.com --dns=223.5.5.5 --dns-option=use-vc --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/dns/Dockerfile ${TESTSDIR}/bud/dns + expect_output --substring "search example.com" + expect_output --substring "nameserver 223.5.5.5" + expect_output --substring "options use-vc" + buildah rm -a buildah rmi -a -f } @@ -35,6 +34,7 @@ load helpers run_buildah bud -t testbud2 --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/dockerignore2 run_buildah bud -t testbud3 --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/dockerignore3 + expect_output --substring "CUT HERE" run sed -e '/^CUT HERE/,/^CUT HERE/p' -e 'd' <<< "$output" run sed '/CUT HERE/d' <<< "$output" @@ -60,10 +60,10 @@ load helpers @test "bud with --layers and --no-cache flags" { cp -a ${TESTSDIR}/bud/use-layers ${TESTDIR}/use-layers - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 8 - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 10 run_buildah --log-level=error inspect --format "{{index .Docker.ContainerConfig.Env 1}}" test1 @@ -75,25 +75,25 @@ load helpers run_buildah --log-level=error inspect --format "{{.Docker.ContainerConfig.ExposedPorts}}" test2 expect_output "map[8080/tcp:{}]" - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.2 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.2 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 12 mkdir -p ${TESTDIR}/use-layers/mount/subdir - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test4 -f Dockerfile.3 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test4 -f Dockerfile.3 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 14 - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test5 -f Dockerfile.3 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test5 -f Dockerfile.3 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 15 touch ${TESTDIR}/use-layers/mount/subdir/file.txt - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test6 -f Dockerfile.3 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test6 -f Dockerfile.3 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 17 - buildah bud --signature-policy ${TESTSDIR}/policy.json --no-cache -t test7 -f Dockerfile.2 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --no-cache -t test7 -f Dockerfile.2 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 18 @@ -101,11 +101,11 @@ load helpers } @test "bud with --layers and single and two line Dockerfiles" { - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.5 ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.5 ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 3 - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.6 ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.6 ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 4 @@ -120,24 +120,23 @@ load helpers mkdir -p ${TESTDIR}/use-layers/date date > ${TESTDIR}/use-layers/date/data - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 6 - [ "${status}" -eq 0 ] # The second time through, the layers should all get reused. - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 6 # The third time through, the layers should all get reused, but we'll have a new line of output for the new name. - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 7 # Both interim images will be different, and all of the layers in the final image will be different. uuidgen > ${TESTDIR}/use-layers/uuid/data date > ${TESTDIR}/use-layers/date/data - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 11 # No leftover containers, just the header line. @@ -152,7 +151,7 @@ load helpers [ "${status}" -eq 0 ] # Layers won't get reused because this build won't use caching. - buildah bud --signature-policy ${TESTSDIR}/policy.json -t test4 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t test4 -f Dockerfile.multistage-copy ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 12 @@ -207,16 +206,16 @@ load helpers cp -a ${TESTSDIR}/bud/use-layers ${TESTDIR}/use-layers echo 'echo "Hello World!"' > ${TESTDIR}/use-layers/hello.sh ln -s hello.sh ${TESTDIR}/use-layers/hello_world.sh - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.4 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.4 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 4 - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.4 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.4 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 5 echo 'echo "Hello Cache!"' > ${TESTDIR}/use-layers/hello.sh - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 -f Dockerfile.4 ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test2 -f Dockerfile.4 ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 7 @@ -228,11 +227,11 @@ load helpers mkdir ${TESTDIR}/use-layers/blah ln -s ${TESTSDIR}/policy.json ${TESTDIR}/use-layers/blah/policy.json - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.dangling-symlink ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test -f Dockerfile.dangling-symlink ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 3 - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.dangling-symlink ${TESTDIR}/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 -f Dockerfile.dangling-symlink ${TESTDIR}/use-layers run_buildah --log-level=error images -a expect_line_count 4 @@ -247,22 +246,22 @@ load helpers @test "bud with --layers and --build-args" { # base plus 3, plus the header line - buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=0 --layers -t test -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=0 --layers -t test -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 5 # two more, starting at the "echo $user" instruction - buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=1 --layers -t test1 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=1 --layers -t test1 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 7 # one more, because we added a new name to the same image - buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=1 --layers -t test2 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --build-arg=user=1 --layers -t test2 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 8 # two more, starting at the "echo $user" instruction - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.build-args ${TESTSDIR}/bud/use-layers run_buildah --log-level=error images -a expect_line_count 10 @@ -270,11 +269,11 @@ load helpers } @test "bud with --rm flag" { - buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test1 ${TESTSDIR}/bud/use-layers run_buildah --log-level=error containers expect_line_count 1 - buildah bud --signature-policy ${TESTSDIR}/policy.json --rm=false --layers -t test2 ${TESTSDIR}/bud/use-layers + run_buildah bud --signature-policy ${TESTSDIR}/policy.json --rm=false --layers -t test2 ${TESTSDIR}/bud/use-layers run_buildah --log-level=error containers expect_line_count 7 @@ -301,10 +300,10 @@ load helpers } @test "bud from base image should have base image ENV also" { - buildah bud --signature-policy ${TESTSDIR}/policy.json -t test -f Dockerfile.check-env ${TESTSDIR}/bud/env + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t test -f Dockerfile.check-env ${TESTSDIR}/bud/env cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json test) - buildah config --env random=hello,goodbye ${cid} - buildah commit --signature-policy ${TESTSDIR}/policy.json ${cid} test1 + run_buildah config --env random=hello,goodbye ${cid} + run_buildah commit --signature-policy ${TESTSDIR}/policy.json ${cid} test1 run_buildah --log-level=error inspect --format '{{index .Docker.ContainerConfig.Env 1}}' test1 expect_output "foo=bar" run_buildah --log-level=error inspect --format '{{index .Docker.ContainerConfig.Env 2}}' test1 @@ -315,7 +314,7 @@ load helpers @test "bud-from-scratch" { target=scratch-image - buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch cid=$(buildah from ${target}) buildah rm ${cid} buildah rmi $(buildah --log-level=error images -q) @@ -325,7 +324,7 @@ load helpers @test "bud-from-scratch-iid" { target=scratch-image - buildah bud --iidfile ${TESTDIR}/output.iid --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch + run_buildah bud --iidfile ${TESTDIR}/output.iid --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch iid=$(cat ${TESTDIR}/output.iid) cid=$(buildah from ${iid}) buildah rm ${cid} @@ -336,7 +335,7 @@ load helpers @test "bud-from-scratch-label" { target=scratch-image - buildah bud --label "test=label" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch + run_buildah bud --label "test=label" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch run_buildah --log-level=error inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target} expect_output 'map["test":"label"]' @@ -345,7 +344,7 @@ load helpers @test "bud-from-scratch-annotation" { target=scratch-image - buildah bud --annotation "test=annotation1,annotation2=z" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch + run_buildah bud --annotation "test=annotation1,annotation2=z" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch run_buildah --log-level=error inspect --format '{{printf "%q" .ImageAnnotations}}' ${target} expect_output 'map["test":"annotation1,annotation2=z"]' buildah rmi ${target} @@ -357,34 +356,31 @@ load helpers run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/from-scratch/Dockerfile2 -t ${target} ${TESTSDIR}/bud/from-scratch cid=$(buildah from ${target}) run_buildah --log-level=error images + expect_line_count 3 run_buildah rm ${cid} - expect_line_count 2 + expect_line_count 1 } @test "bud-from-multiple-files-one-from" { target=scratch-image - buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch -f ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.scratch cmp $root/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom - run test -s $root/etc/passwd - echo "$output" - [ "$status" -ne 0 ] + test ! -s $root/etc/passwd buildah rm ${cid} buildah rmi $(buildah --log-level=error images -q) run_buildah --log-level=error images -q expect_output "" target=alpine-image - buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.alpine -f Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.alpine -f Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile1 ${TESTSDIR}/bud/from-multiple-files/Dockerfile1.alpine cmp $root/Dockerfile2.nofrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.nofrom - run test -s $root/etc/passwd - echo "$output" - [ "$status" -eq 0 ] + test -s $root/etc/passwd buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q @@ -393,32 +389,24 @@ load helpers @test "bud-from-multiple-files-two-froms" { target=scratch-image - buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.scratch -f Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.scratch -f Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files cid=$(buildah from ${target}) root=$(buildah mount ${cid}) - run test -s $root/Dockerfile1 - echo "$output" - [ "$status" -ne 0 ] + test ! -s $root/Dockerfile1 cmp $root/Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom - run test -s $root/etc/passwd - echo "$output" - [ "$status" -eq 0 ] + test -s $root/etc/passwd buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q expect_output "" target=alpine-image - buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.alpine -f Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files + run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1.alpine -f Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files cid=$(buildah from ${target}) root=$(buildah mount ${cid}) - run test -s $root/Dockerfile1 - echo "$output" - [ "$status" -ne 0 ] + test ! -s $root/Dockerfile1 cmp $root/Dockerfile2.withfrom ${TESTSDIR}/bud/from-multiple-files/Dockerfile2.withfrom - run test -s $root/etc/passwd - echo "$output" - [ "$status" -eq 0 ] + test -s $root/etc/passwd buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q @@ -432,8 +420,7 @@ load helpers cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile.index ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.index - run test -s $root/etc/passwd - [ "$status" -eq 0 ] + test -s $root/etc/passwd buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q @@ -444,8 +431,7 @@ load helpers cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.name - run test -s $root/etc/passwd - [ "$status" -ne 0 ] + test ! -s $root/etc/passwd buildah rm ${cid} buildah rmi $(buildah --log-level=error images -q) run_buildah --log-level=error images -q @@ -470,8 +456,7 @@ load helpers cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile.index ${TESTSDIR}/bud/multi-stage-builds-small-as/Dockerfile.index - run test -s $root/etc/passwd - [ "$status" -eq 0 ] + test -s $root/etc/passwd buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q @@ -482,8 +467,7 @@ load helpers cid=$(buildah from ${target}) root=$(buildah mount ${cid}) cmp $root/Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds-small-as/Dockerfile.name - run test -s $root/etc/passwd - [ "$status" -ne 0 ] + test ! -s $root/etc/passwd buildah rm ${cid} buildah rmi $(buildah --log-level=error images -q) run_buildah --log-level=error images -q @@ -512,13 +496,11 @@ load helpers cid=$(buildah from ${target}) root=$(buildah mount ${cid}) test -s $root/vol/subvol/subsubvol/subsubvolfile - run test -s $root/vol/subvol/subvolfile - [ "$status" -ne 0 ] + test ! -s $root/vol/subvol/subvolfile test -s $root/vol/volfile test -s $root/vol/Dockerfile test -s $root/vol/Dockerfile2 - run test -s $root/vol/anothervolfile - [ "$status" -ne 0 ] + test ! -s $root/vol/anothervolfile buildah rm ${cid} buildah rmi -a run_buildah --log-level=error images -q @@ -654,8 +636,7 @@ load helpers buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/volume-perms cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) root=$(buildah mount ${cid}) - run test -s $root/vol/subvol/subvolfile - [ "$status" -ne 0 ] + test ! -s $root/vol/subvol/subvolfile run stat -c %f $root/vol/subvol echo "$output" [ "$status" -eq 0 ] @@ -860,7 +841,7 @@ load helpers @test "bud with ENTRYPOINT and empty RUN" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.entrypoint-empty-run ${TESTSDIR}/bud/run-scenarios - expect_output --substring "error building at step" + expect_output --substring "error building at STEP" } @test "bud with CMD and RUN" { @@ -875,7 +856,7 @@ load helpers @test "bud with CMD and empty RUN" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.cmd-empty-run ${TESTSDIR}/bud/run-scenarios - expect_output --substring "error building at step" + expect_output --substring "error building at STEP" } @test "bud with ENTRYPOINT, CMD and RUN" { @@ -890,7 +871,7 @@ load helpers @test "bud with ENTRYPOINT, CMD and empty RUN" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/run-scenarios/Dockerfile.entrypoint-cmd-empty-run ${TESTSDIR}/bud/run-scenarios - expect_output --substring "error building at step" + expect_output --substring "error building at STEP" } # Determines if a variable set with ENV is available to following commands in the Dockerfile @@ -1340,9 +1321,7 @@ load helpers ctr=$(buildah --log-level=error from --signature-policy ${TESTSDIR}/policy.json ${target}) mnt=$(buildah --log-level=error mount ${ctr}) - run test -e $mnt/usr/local/bin/composer - echo "$output" - [ "$status" -eq 0 ] + test -e $mnt/usr/local/bin/composer } @test "bud-target" { @@ -1369,18 +1348,17 @@ load helpers # pull the base image directly, so that we don't record it being written to local storage in the next step run_buildah pull --signature-policy ${TESTSDIR}/policy.json alpine # okay, build an image with two stages - run_buildah bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds + run_buildah --log-level=debug bud --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds # debug messages should only record us creating one new image: the one for the second stage, since we don't base anything on the first run grep "created new image ID" <<< "$output" - echo "$output" - test "${#lines[@]}" -eq 1 + expect_line_count 1 } @test "bud-multi-stage-cache-nocontainer" { # first time through, quite normal run_buildah bud --layers -t base --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.rebase ${TESTSDIR}/bud/multi-stage-builds # second time through, everything should be cached, and we shouldn't create a container based on the final image - run_buildah bud --layers -t base --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.rebase ${TESTSDIR}/bud/multi-stage-builds + run_buildah --log-level=debug bud --layers -t base --signature-policy ${TESTSDIR}/policy.json -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.rebase ${TESTSDIR}/bud/multi-stage-builds # skip everything up through the final COMMIT step, and make sure we didn't log a "Container ID:" after it run sed '0,/COMMIT base/ d' <<< "$output" echo "$output" @@ -1695,10 +1673,10 @@ load helpers skip "BUILDAH_ISOLATION = $BUILDAH_ISOLATION" fi target=alpine-image - mkdir ${TESTSDIR}/foo + rm -rf ${TESTSDIR}/foo + mkdir -p ${TESTSDIR}/foo mknod ${TESTSDIR}/foo/null c 1 3 run_buildah bud --signature-policy ${TESTSDIR}/policy.json --device ${TESTSDIR}/foo:/dev/fuse -t ${target} -f ${TESTSDIR}/bud/device/Dockerfile ${TESTSDIR}/bud/device - [ "${status}" -eq 0 ] expect_output --substring "null" buildah rmi ${target} diff --git a/tests/copy.bats b/tests/copy.bats index cfc2703293b..8d8caeb411f 100644 --- a/tests/copy.bats +++ b/tests/copy.bats @@ -105,7 +105,10 @@ load helpers } @test "copy-url-mtime" { + # Create a file with random content and a non-now timestamp (so we can + # can trust that buildah correctly set mtime on copy) createrandom ${TESTDIR}/randomfile + touch -t 201910310123.45 ${TESTDIR}/randomfile cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json scratch) buildah config --workingdir / $cid @@ -115,10 +118,16 @@ load helpers root=$(buildah mount $cid) test -s $root/urlfile cmp ${TESTDIR}/randomfile $root/urlfile - run test -nt ${TESTDIR}/randomfile $root/urlfile - [ "$status" -ne 0 ] - run test -ot ${TESTDIR}/randomfile $root/urlfile - [ "$status" -ne 0 ] + + # Compare timestamps. Display them in human-readable form, so if there's + # a mismatch it will be shown in the test log. + mtime_randomfile=$(stat --format %y ${TESTDIR}/randomfile) + mtime_urlfile=$(stat --format %y $root/urlfile) + + echo "mtime[randomfile] = $mtime_randomfile" + echo "mtime[urlfile] = $mtime_urlfile" + test "$mtime_randomfile" = "$mtime_urlfile" + buildah rm $cid } diff --git a/tests/formats.bats b/tests/formats.bats index c23b483b0e7..d1863796c13 100644 --- a/tests/formats.bats +++ b/tests/formats.bats @@ -2,33 +2,66 @@ load helpers +################### +# check_imgtype # shortcut for running 'imgtype' and verifying image +################### +function check_imgtype() { + # First argument: image name + image="$1" + + # Second argument: expected image type, 'oci' or 'docker' + imgtype_oci="application/vnd.oci.image.manifest.v1+json" + imgtype_dkr="application/vnd.docker.distribution.manifest.v2+json" + + expect="" + case "$2" in + oci) want=$imgtype_oci; reject=$imgtype_dkr;; + docker) want=$imgtype_dkr; reject=$imgtype_oci;; + *) die "Internal error: unknown image type '$2'";; + esac + + # First test: run imgtype with expected type, confirm exit 0 + no output + echo "\$ imgtype -expected-manifest-type $want $image" + run imgtype -expected-manifest-type $want $image + echo "$output" + if [[ $status -ne 0 ]]; then + die "exit status is $status (expected 0)" + fi + expect_output "" "Checking imagetype($image) == $2" + + # Second test: the converse. Run imgtype with the WRONG expected type, + # confirm error message and exit status 1 + echo "\$ imgtype -expected-manifest-type $reject $image [opposite test]" + run imgtype -expected-manifest-type $reject $image + echo "$output" + if [[ $status -ne 1 ]]; then + die "exit status is $status (expected 1)" + fi + + # Can't embed entire string because the '+' sign is interpreted as regex + expect_output --substring \ + "level=error msg=\"expected .* type \\\\\".*, got " \ + "Checking imagetype($image) == $2" +} + + @test "write-formats" { cid=$(buildah from --pull=false --signature-policy ${TESTSDIR}/policy.json scratch) - buildah commit --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-default - buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker - buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci - imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-default - imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-oci - imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-docker - run imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-default - [ "$status" -ne 0 ] - run imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-oci - [ "$status" -ne 0 ] - run imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-docker - [ "$status" -ne 0 ] + run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-default + run_buildah commit --format docker --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-docker + run_buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid scratch-image-oci + + check_imgtype scratch-image-default oci + check_imgtype scratch-image-oci oci + check_imgtype scratch-image-docker docker } @test "bud-formats" { - buildah build-using-dockerfile --signature-policy ${TESTSDIR}/policy.json -t scratch-image-default -f Dockerfile bud/from-scratch - buildah build-using-dockerfile --format docker --signature-policy ${TESTSDIR}/policy.json -t scratch-image-docker -f Dockerfile bud/from-scratch - buildah build-using-dockerfile --format oci --signature-policy ${TESTSDIR}/policy.json -t scratch-image-oci -f Dockerfile bud/from-scratch - imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-default - imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-oci - imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-docker - run imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-default - [ "$status" -ne 0 ] - run imgtype -expected-manifest-type application/vnd.docker.distribution.manifest.v2+json scratch-image-oci - [ "$status" -ne 0 ] - run imgtype -expected-manifest-type application/vnd.oci.image.manifest.v1+json scratch-image-docker - [ "$status" -ne 0 ] + run_buildah build-using-dockerfile --signature-policy ${TESTSDIR}/policy.json -t scratch-image-default -f Dockerfile ${TESTSDIR}/bud/from-scratch + run_buildah build-using-dockerfile --format docker --signature-policy ${TESTSDIR}/policy.json -t scratch-image-docker -f Dockerfile ${TESTSDIR}/bud/from-scratch + run_buildah build-using-dockerfile --format oci --signature-policy ${TESTSDIR}/policy.json -t scratch-image-oci -f Dockerfile ${TESTSDIR}/bud/from-scratch + + check_imgtype scratch-image-default oci + check_imgtype scratch-image-oci oci + check_imgtype scratch-image-docker docker } diff --git a/tests/helpers.bash b/tests/helpers.bash index 73d237fc9eb..47c2fb377fe 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -44,11 +44,11 @@ function createrandom() { } function buildah() { - ${BUILDAH_BINARY} --log-level=debug --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@" + ${BUILDAH_BINARY} --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@" } function imgtype() { - ${IMGTYPE_BINARY} -debug -root ${TESTDIR}/root -runroot ${TESTDIR}/runroot -storage-driver ${STORAGE_DRIVER} "$@" + ${IMGTYPE_BINARY} -root ${TESTDIR}/root -runroot ${TESTDIR}/runroot -storage-driver ${STORAGE_DRIVER} "$@" } ################# @@ -85,7 +85,7 @@ function run_buildah() { # stdout is only emitted upon error; this echo is to help a debugger echo "\$ $BUILDAH_BINARY $*" - run timeout --foreground --kill=10 $BUILDAH_TIMEOUT ${BUILDAH_BINARY} --log-level=debug --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@" + run timeout --foreground --kill=10 $BUILDAH_TIMEOUT ${BUILDAH_BINARY} --registries-conf ${TESTSDIR}/registries.conf --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} "$@" # without "quotes", multiple lines are glommed together into one if [ -n "$output" ]; then echo "$output" @@ -190,7 +190,7 @@ function expect_output() { local -a actual_split readarray -t actual_split <<<"$actual" printf "#/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" >&2 - printf "#| FAIL: $testname\n" >&2 + printf "#| FAIL: %s\n" "$testname" >&2 printf "#| expected: '%s'\n" "$expect" >&2 printf "#| actual: '%s'\n" "${actual_split[0]}" >&2 local line diff --git a/tests/version.bats b/tests/version.bats index 5a4cf718bac..97b444c7023 100644 --- a/tests/version.bats +++ b/tests/version.bats @@ -12,8 +12,7 @@ load helpers fi bversion=$(buildah version | awk '/^Version:/ { print $NF }') rversion=$(cat ${TESTSDIR}/../contrib/rpm/buildah.spec | awk '/^Version:/ { print $NF }') - run test "${bversion}" = "${rversion}" -o "${bversion}" = "${rversion}-dev" - [ "$status" -eq 0 ] + test "${bversion}" = "${rversion}" -o "${bversion}" = "${rversion}-dev" } @test "buildah version current in .spec file changelog" { @@ -21,6 +20,5 @@ load helpers skip "No source dir available" fi bversion=$(buildah version | awk '/^Version:/ { print $NF }') - run bash -c "grep -A1 ^%changelog ${TESTSDIR}/../contrib/rpm/buildah.spec | grep -q \" ${bversion}-.*$\"" - [ "$status" -eq 0 ] + grep -A1 ^%changelog ${TESTSDIR}/../contrib/rpm/buildah.spec | grep -q " ${bversion}-" }