From 021d6072825ff94ce7fe0bd40e8414af62fac33d Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Fri, 5 Apr 2019 09:59:54 -0600 Subject: [PATCH] rename 'is' to 'expect_output' ...and make the "$output" argument implicit, as well as the description text. This greatly simplifies its invocation. Also: make it test for exact matches unless --substring option is passed; this eases my mind about a few potentially ambiguous situations such as the one in #1464. Also: add comments to two truth-table check functions Also: reorder some config checks alphabetically, for ease of reading. Thanks to Tom Sweeney for the suggestions and encouragement. Signed-off-by: Ed Santiago Closes: #1492 Approved by: rhatdan --- tests/basic.bats | 2 +- tests/bud.bats | 174 +++++++++++++++++++++--------------------- tests/commit.bats | 6 +- tests/config.bats | 27 +++---- tests/from.bats | 20 ++--- tests/helpers.bash | 55 +++++++++---- tests/images.bats | 8 +- tests/mount.bats | 6 +- tests/namespaces.bats | 8 +- tests/pull.bats | 24 +++--- tests/push.bats | 2 +- tests/registries.bats | 2 +- tests/rename.bats | 8 +- tests/rm.bats | 8 +- tests/rmi.bats | 24 +++--- tests/run.bats | 68 ++++++++--------- tests/secrets.bats | 4 +- tests/selinux.bats | 8 +- tests/squash.bats | 3 +- 19 files changed, 243 insertions(+), 214 deletions(-) diff --git a/tests/basic.bats b/tests/basic.bats index 9e8a6bfb3f7..d256b518e33 100644 --- a/tests/basic.bats +++ b/tests/basic.bats @@ -106,5 +106,5 @@ load helpers [ "$output" != "" ] run_buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "output from buildah images -q" + expect_output "" } diff --git a/tests/bud.bats b/tests/bud.bats index d3cf182635d..8ae2f0f8e25 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -44,9 +44,9 @@ load helpers run_buildah --debug=false images -a expect_line_count 8 run_buildah --debug=false inspect --format "{{index .Docker.ContainerConfig.Env 1}}" test2 - is "$output" "foo=bar" "ContainerConfig.Env" + expect_output "foo=bar" run_buildah --debug=false inspect --format "{{.Docker.ContainerConfig.ExposedPorts}}" test2 - is "$output" "map[8080/tcp:{}]" "ContainerConfig.ExposedPorts" + expect_output "map[8080/tcp:{}]" buildah bud --signature-policy ${TESTSDIR}/policy.json --layers -t test3 -f Dockerfile.2 ${TESTDIR}/use-layers run_buildah --debug=false images -a @@ -180,7 +180,7 @@ load helpers @test "bud --layers with non-existent/down registry" { run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json --force-rm --layers -t test1 -f Dockerfile.non-existent-registry ${TESTSDIR}/bud/use-layers - is "$output" ".*no such host" "expecting non-existent-registry" + expect_output --substring "no such host" } @test "bud from base image should have base image ENV also" { @@ -189,9 +189,9 @@ load helpers buildah config --env random=hello,goodbye ${cid} buildah commit --signature-policy ${TESTSDIR}/policy.json ${cid} test1 run_buildah --debug=false inspect --format '{{index .Docker.ContainerConfig.Env 1}}' test1 - is "$output" "foo=bar" "image environment, index 1" + expect_output "foo=bar" run_buildah --debug=false inspect --format '{{index .Docker.ContainerConfig.Env 2}}' test1 - is "$output" "random=hello,goodbye" "image environment, index 2" + expect_output "random=hello,goodbye" buildah rm ${cid} buildah rmi -a -f } @@ -203,7 +203,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "output from buildah images" + expect_output "" } @test "bud-from-scratch-iid" { @@ -214,14 +214,14 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @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 --debug=false inspect --format '{{printf "%q" .Docker.Config.Labels}}' ${target} - is "$output" 'map["test":"label"]' "buildah inspect" + expect_output 'map["test":"label"]' buildah rmi ${target} } @@ -230,7 +230,7 @@ load helpers target=scratch-image buildah bud --annotation "test=annotation1,annotation2=z" --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch run_buildah --debug=false inspect --format '{{printf "%q" .ImageAnnotations}}' ${target} - is "$output" 'map["test":"annotation1,annotation2=z"]' "buildah inspect" + expect_output 'map["test":"annotation1,annotation2=z"]' buildah rmi ${target} } @@ -247,7 +247,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah 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 @@ -261,7 +261,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-from-multiple-files-two-froms" { @@ -279,7 +279,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah 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 @@ -296,7 +296,7 @@ load helpers buildah rmi -a run_buildah --debug=false images -q echo "$output" - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-multi-stage-builds" { @@ -310,7 +310,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" target=multi-stage-name buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds @@ -322,7 +322,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" target=multi-stage-mixed buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/multi-stage-builds/Dockerfile.mixed ${TESTSDIR}/bud/multi-stage-builds @@ -334,7 +334,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-multi-stage-builds-small-as" { @@ -348,7 +348,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" target=multi-stage-name buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.name ${TESTSDIR}/bud/multi-stage-builds-small-as @@ -360,7 +360,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" target=multi-stage-mixed buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/multi-stage-builds-small-as/Dockerfile.mixed ${TESTSDIR}/bud/multi-stage-builds-small-as @@ -372,7 +372,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-preserve-subvolumes" { @@ -395,7 +395,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-http-Dockerfile" { @@ -407,7 +407,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-http-context-with-Dockerfile" { @@ -419,7 +419,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-http-context-dir-with-Dockerfile-pre" { @@ -431,7 +431,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-http-context-dir-with-Dockerfile-post" { @@ -443,7 +443,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-git-context" { @@ -462,7 +462,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-github-context" { @@ -475,7 +475,7 @@ load helpers buildah --debug=false images -q buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-additional-tags" { @@ -492,7 +492,7 @@ load helpers buildah rm ${cid} buildah rmi -f $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-volume-perms" { @@ -513,7 +513,7 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-from-glob" { @@ -526,43 +526,43 @@ load helpers buildah rm ${cid} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-maintainer" { target=alpine-image buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/maintainer run_buildah --debug=false inspect --type=image --format '{{.Docker.Author}}' ${target} - is "$output" "kilroy" "buildah inspect - .Docker.Author" + expect_output "kilroy" run_buildah --debug=false inspect --type=image --format '{{.OCIv1.Author}}' ${target} - is "$output" "kilroy" "buildah inspect - .OCIv1.Author" + expect_output "kilroy" buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-unrecognized-instruction" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/unrecognized - is "$output" ".*BOGUS" "buildah bud - unrecognized" + expect_output --substring "BOGUS" buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud-shell" { target=alpine-image buildah bud --format docker --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/shell run_buildah --debug=false inspect --type=image --format '{{printf "%q" .Docker.Config.Shell}}' ${target} - is "$output" '["/bin/sh" "-c"]' ".Docker.Config.Shell (original)" + expect_output '["/bin/sh" "-c"]' ".Docker.Config.Shell (original)" ctr=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) run_buildah --debug=false config --shell "/bin/bash -c" ${ctr} run_buildah --debug=false inspect --type=container --format '{{printf "%q" .Docker.Config.Shell}}' ${ctr} - is "$output" '["/bin/bash" "-c"]' ".Docker.Config.Shell (changed)" + expect_output '["/bin/bash" "-c"]' ".Docker.Config.Shell (changed)" buildah rm ${ctr} buildah rmi -a run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud with symlinks" { @@ -636,7 +636,7 @@ load helpers @test "bud with ENTRYPOINT and RUN" { target=alpine-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.entrypoint-run ${TESTSDIR}/bud/run-scenarios - is "$output" ".*unique.test.string" "buildah bud run-scenarios" + expect_output --substring "unique.test.string" cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) buildah rm ${cid} buildah rmi ${target} @@ -645,13 +645,13 @@ 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 - is "$output" ".*error building at step" "buildah bud output" + expect_output --substring "error building at step" } @test "bud with CMD and RUN" { target=alpine-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/run-scenarios/Dockerfile.cmd-run ${TESTSDIR}/bud/run-scenarios - is "$output" ".*unique.test.string" "buildah bud output" + expect_output --substring "unique.test.string" cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) buildah rm ${cid} buildah rmi ${target} @@ -660,13 +660,13 @@ 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 - is "$output" ".*error building at step" "buildah bud output" + expect_output --substring "error building at step" } @test "bud with ENTRYPOINT, CMD and RUN" { target=alpine-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/run-scenarios/Dockerfile.entrypoint-cmd-run ${TESTSDIR}/bud/run-scenarios - is "$output" ".*unique.test.string" "buildah bud output" + expect_output --substring "unique.test.string" cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) buildah rm ${cid} buildah rmi ${target} @@ -675,14 +675,14 @@ 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 - is "$output" ".*error building at step" "buildah bud output" + expect_output --substring "error building at step" } # Determines if a variable set with ENV is available to following commands in the Dockerfile @test "bud access ENV variable defined in same source file" { target=env-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/env/Dockerfile.env-same-file ${TESTSDIR}/bud/env - is "$output" ".*:unique.test.string:" "buildah bud output" + expect_output --substring ":unique.test.string:" cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json ${target}) buildah rm ${cid} buildah rmi ${target} @@ -694,7 +694,7 @@ load helpers target=env-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${from_target} -f ${TESTSDIR}/bud/env/Dockerfile.env-same-file ${TESTSDIR}/bud/env run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/env/Dockerfile.env-from-image ${TESTSDIR}/bud/env - is "$output" ".*@unique.test.string@" "buildah bud output" + expect_output --substring "@unique.test.string@" from_cid=$(buildah from ${from_target}) cid=$(buildah from ${target}) buildah rm ${from_cid} ${cid} @@ -750,7 +750,7 @@ load helpers @test "bud with --cpu-shares flag, invalid argument" { target=bud-flag run_buildah 1 bud --cpu-shares bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch - is "$output" ".*invalid argument \"bogus\" for " "buildah bud output" + expect_output --substring "invalid argument \"bogus\" for " } @test "bud with --cpu-shares flag, valid argument" { @@ -769,7 +769,7 @@ load helpers @test "bud with --cpu-shares short flag (-c), invalid argument" { target=bud-flag run_buildah 1 bud -c bogus --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/from-scratch/Dockerfile ${TESTSDIR}/bud/from-scratch - is "$output" "invalid argument \"bogus\" for " "buildah bud output" + expect_output --substring "invalid argument \"bogus\" for " } @test "bud with --cpu-shares short flag (-c), valid argument" { @@ -784,7 +784,7 @@ load helpers target=onbuild buildah bud --format docker --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/onbuild run_buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.OnBuild}}' ${target} - is "$output" '["RUN touch /onbuild1" "RUN touch /onbuild2"]' ".Config.OnBuild" + expect_output '["RUN touch /onbuild1" "RUN touch /onbuild2"]' cid=$(buildah from ${target}) root=$(buildah mount ${cid}) run ls ${root}/onbuild1 ${root}/onbuild2 @@ -796,7 +796,7 @@ load helpers target=onbuild-image2 buildah bud --format docker --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile1 ${TESTSDIR}/bud/onbuild run_buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.OnBuild}}' ${target} - is "$output" '["RUN touch /onbuild3"]' ".Config.OnBuild" + expect_output '["RUN touch /onbuild3"]' cid=$(buildah from ${target}) root=$(buildah mount ${cid}) run ls ${root}/onbuild1 ${root}/onbuild2 ${root}/onbuild3 @@ -809,7 +809,7 @@ load helpers target=onbuild-image3 buildah commit --signature-policy ${TESTSDIR}/policy.json --format docker ${cid} ${target} run_buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.OnBuild}}' ${target} - is "$output" '["RUN touch /onbuild4"]' ".Config.OnBuild" + expect_output '["RUN touch /onbuild4"]' buildah rm ${cid} buildah rmi --all } @@ -817,39 +817,37 @@ load helpers @test "bud-onbuild-layers" { target=onbuild buildah bud --format docker --signature-policy ${TESTSDIR}/policy.json --layers -t ${target} -f Dockerfile2 ${TESTSDIR}/bud/onbuild - run buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.OnBuild}}' ${target} - echo "$output" - [ "$status" -eq 0 ] - [ "$output" = '["RUN touch /onbuild1" "RUN touch /onbuild2"]' ] + run_buildah --debug=false inspect --format '{{printf "%q" .Docker.Config.OnBuild}}' ${target} + expect_output '["RUN touch /onbuild1" "RUN touch /onbuild2"]' } @test "bud-logfile" { rm -f ${TESTDIR}/logfile run_buildah bud --logfile ${TESTDIR}/logfile --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/preserve-volumes - is "$output" "" "buildah bud output" + expect_output "" test -s ${TESTDIR}/logfile } @test "bud with ARGS" { target=alpine-image run_buildah --debug=false bud -q --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.args ${TESTSDIR}/bud/run-scenarios - is "$output" ".*arg_value" "buildah bud output" + expect_output --substring "arg_value" } @test "bud with unused ARGS" { target=alpine-image run_buildah --debug=false bud -q --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.multi-args --build-arg USED_ARG=USED_VALUE ${TESTSDIR}/bud/run-scenarios - is "$output" ".*USED_VALUE" "buildah bud output" + expect_output --substring "USED_VALUE" [[ ! "$output" =~ "one or more build args were not consumed: [UNUSED_ARG]" ]] run_buildah --debug=false bud -q --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.multi-args --build-arg USED_ARG=USED_VALUE --build-arg UNUSED_ARG=whaaaat ${TESTSDIR}/bud/run-scenarios - is "$output" ".*USED_VALUE" "buildah bud output" - is "$output" ".*one or more build args were not consumed: \[UNUSED_ARG\]" "buildah bud output" + expect_output --substring "USED_VALUE" + expect_output --substring "one or more build args were not consumed: \[UNUSED_ARG\]" } @test "bud with multi-value ARGS" { target=alpine-image run_buildah --debug=false bud -q --signature-policy ${TESTSDIR}/policy.json -t ${target} -f Dockerfile.multi-args --build-arg USED_ARG=plugin1,plugin2,plugin3 ${TESTSDIR}/bud/run-scenarios - is "$output" ".*plugin1,plugin2,plugin3" "buildah bud output" + expect_output --substring "plugin1,plugin2,plugin3" [[ ! "$output" =~ "one or more build args were not consumed: [UNUSED_ARG]" ]] } @@ -864,7 +862,7 @@ load helpers buildah rm ${cid} buildah rmi $(buildah --debug=false images -q) run_buildah --debug=false images -q - is "$output" "" "buildah images -q" + expect_output "" } @test "bud with preprocessor" { @@ -880,89 +878,89 @@ load helpers @test "bud-with-rejected-name" { target=ThisNameShouldBeRejected run_buildah 1 --debug=false bud -q --signature-policy ${TESTSDIR}/policy.json -t ${target} ${TESTSDIR}/bud/from-scratch - is "$output" ".*must be lower" "buildah bud output" + expect_output --substring "must be lower" } @test "bud with chown copy" { imgName=alpine-image ctrName=alpine-chown run_buildah --debug=false bud --signature-policy ${TESTSDIR}/policy.json -t ${imgName} ${TESTSDIR}/bud/copy-chown - is "$output" ".*user:2367 group:3267" "buildah bud output" + expect_output --substring "user:2367 group:3267" run_buildah --debug=false from --name ${ctrName} ${imgName} run_buildah --debug=false run alpine-chown -- stat -c '%u' /tmp/copychown.txt # Validate that output starts with "2367" - is "$output" "2367.*" "output from stat" + expect_output --substring "2367" run_buildah --debug=false run alpine-chown -- stat -c '%g' /tmp/copychown.txt # Validate that output starts with "3267" - is "$output" "3267.*" "output from stat" + expect_output --substring "3267" } @test "bud with chown add" { imgName=alpine-image ctrName=alpine-chown run_buildah --debug=false bud --signature-policy ${TESTSDIR}/policy.json -t ${imgName} ${TESTSDIR}/bud/add-chown - is "$output" ".*user:2367 group:3267" "buildah bud output" + expect_output --substring "user:2367 group:3267" run_buildah --debug=false from --name ${ctrName} ${imgName} run_buildah --debug=false run alpine-chown -- stat -c '%u' /tmp/addchown.txt # Validate that output starts with "2367" - is "$output" "2367.*" "output from stat" + expect_output --substring "2367" run_buildah --debug=false run alpine-chown -- stat -c '%g' /tmp/addchown.txt # Validate that output starts with "3267" - is "$output" "3267.*" "output from stat" + expect_output --substring "3267" } @test "bud with ADD file construct" { buildah --debug=false bud --signature-policy ${TESTSDIR}/policy.json -t test1 ${TESTSDIR}/bud/add-file run_buildah --debug=false images -a - is "$output" ".*test1" "buildah images -a" + expect_output --substring "test1" ctr=$(buildah --debug=false from --signature-policy ${TESTSDIR}/policy.json test1) run_buildah --debug=false containers -a - is "$output" ".*test1" "buildah containers -a" + expect_output --substring "test1" run_buildah --debug=false run $ctr ls /var/file2 - is "$output" ".*/var/file2" "buildah run ls" + expect_output --substring "/var/file2" } @test "bud with FROM AS construct" { buildah bud --signature-policy ${TESTSDIR}/policy.json -t test1 ${TESTSDIR}/bud/from-as run_buildah --debug=false images -a - is "$output" ".*test1" "buildah images -a" + expect_output --substring "test1" ctr=$(buildah --debug=false from --signature-policy ${TESTSDIR}/policy.json test1) run_buildah --debug=false containers -a - is "$output" ".*test1" "buildah containers -a" + expect_output --substring "test1" run_buildah inspect --format "{{.Docker.ContainerConfig.Env}}" --type image test1 - is "$output" ".*LOCAL=/1" ".ContainerConfig.Env" + expect_output --substring "LOCAL=/1" } @test "bud with FROM AS construct with layers" { buildah bud --layers --signature-policy ${TESTSDIR}/policy.json -t test1 ${TESTSDIR}/bud/from-as run_buildah --debug=false images -a - is "$output" ".*test1" "buildah images -a" + expect_output --substring "test1" ctr=$(buildah --debug=false from --signature-policy ${TESTSDIR}/policy.json test1) run_buildah --debug=false containers -a - is "$output" ".*test1" "buildah containers -a" + expect_output --substring "test1" run_buildah inspect --format "{{.Docker.ContainerConfig.Env}}" --type image test1 - is "$output" ".*LOCAL=/1" ".ContainerConfig.Env" + expect_output --substring "LOCAL=/1" } @test "bud with FROM AS skip FROM construct" { run_buildah --debug=false bud --signature-policy ${TESTSDIR}/policy.json -t test1 -f ${TESTSDIR}/bud/from-as/Dockerfile.skip ${TESTSDIR}/bud/from-as - is "$output" ".*LOCAL=/1" "buildah bud output" - is "$output" ".*LOCAL2=/2" "buildah bud output" + expect_output --substring "LOCAL=/1" + expect_output --substring "LOCAL2=/2" run_buildah --debug=false images -a - is "$output" ".*test1" "buildah images -a" + expect_output --substring "test1" ctr=$(buildah --debug=false from --signature-policy ${TESTSDIR}/policy.json test1) run_buildah --debug=false containers -a - is "$output" ".*test1" "buildah containers -a" + expect_output --substring "test1" mnt=$(buildah mount $ctr) run test -e $mnt/1 @@ -971,25 +969,25 @@ load helpers [ "${status}" -ne 0 ] run_buildah --debug=false inspect --format "{{.Docker.ContainerConfig.Env}}" --type image test1 - is "$output" "[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LOCAL=/1]" ".ContainerConfig.Env" + expect_output "[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LOCAL=/1]" } @test "bud with symlink Dockerfile not specified in file" { target=alpine-image run_buildah bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/symlink ${TESTSDIR}/bud/symlink - is "$output" ".*FROM alpine" "buildah bud output" + expect_output --substring "FROM alpine" } @test "bud with dir for file but no Dockerfile in dir" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/bud/empty-dir ${TESTSDIR}/bud/empty-dir - is "$output" ".*no such file or directory" "buildah bud output" + expect_output --substring "no such file or directory" } @test "bud with bad dir Dockerfile" { target=alpine-image run_buildah 1 bud --signature-policy ${TESTSDIR}/policy.json -t ${target} -f ${TESTSDIR}/baddirname ${TESTSDIR}/baddirname - is "$output" ".*no such file or directory" "buildah bud output" + expect_output --substring "no such file or directory" } @test "bud with ARG before FROM default value" { @@ -1010,7 +1008,7 @@ load helpers threeseconds=$(( 3 * $second )) fiveminutes=$(( 5 * 60 * $second )) tenminutes=$(( 10 * 60 * $second )) - is "$output" '["CMD-SHELL" "curl -f http://localhost/ || exit 1"]'" $tenminutes $fiveminutes $threeseconds 4" "Healthcheck config" + expect_output '["CMD-SHELL" "curl -f http://localhost/ || exit 1"]'" $tenminutes $fiveminutes $threeseconds 4" "Healthcheck config" } @test "bud with unused build arg" { @@ -1045,8 +1043,8 @@ load helpers @test "bud-target" { target=target run_buildah bud --debug=false --signature-policy ${TESTSDIR}/policy.json -t ${target} --target mytarget ${TESTSDIR}/bud/target - is "$output" ".*STEP 1: FROM ubuntu:latest" "buildah bud output" - is "$output" ".*STEP 3: FROM alpine:latest AS mytarget" "buildah bud output" + expect_output --substring "STEP 1: FROM ubuntu:latest" + expect_output --substring "STEP 3: FROM alpine:latest AS mytarget" cid=$(buildah from ${target}) root=$(buildah mount ${cid}) run ls ${root}/2 diff --git a/tests/commit.bats b/tests/commit.bats index 7c827404659..270fbf493a3 100644 --- a/tests/commit.bats +++ b/tests/commit.bats @@ -38,7 +38,7 @@ load helpers @test "commit quiet test" { cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false commit --iidfile /dev/null --signature-policy ${TESTSDIR}/policy.json -q $cid alpine-image - is "$output" "" "no output from commit" + expect_output "" buildah rm $cid buildah rmi -a } @@ -47,7 +47,7 @@ load helpers cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) buildah commit --signature-policy ${TESTSDIR}/policy.json --rm $cid alpine-image run_buildah 1 --debug=false rm $cid - is "$output" ".*error removing container \"alpine-working-container\": error reading build container: container not known" "buildah rm" + expect_output --substring "error removing container \"alpine-working-container\": error reading build container: container not known" buildah rmi -a } @@ -63,7 +63,7 @@ load helpers @test "commit-rejected-name" { cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah 1 --debug=false commit --signature-policy ${TESTSDIR}/policy.json $cid ThisNameShouldBeRejected - is "$output" ".*must be lower" "buildah commit output" + expect_output --substring "must be lower" } @test "commit-no-empty-created-by" { diff --git a/tests/config.bats b/tests/config.bats index d41f17b97c0..efdf536d859 100644 --- a/tests/config.bats +++ b/tests/config.bats @@ -20,10 +20,11 @@ function check_matrix() { local setting=$1 local expect=$2 + # matrix test: all permutations of .Docker.* and .OCIv1.* in all image types for image in docker oci; do for which in Docker OCIv1; do run_buildah --debug=false inspect --type=image --format "{{.$which.$setting}}" scratch-image-$image - is "$output" "$expect" "scratch-image-$image > .$which.$setting" + expect_output "$expect" done done } @@ -144,16 +145,16 @@ function check_matrix() { buildah --debug=false inspect --format '{{.ImageCreatedBy}}' $cid | grep COINCIDENCE - check_matrix 'Config.User' 'likes:things' - check_matrix 'Config.ExposedPorts' 'map[12345:{}]' - check_matrix 'Config.Env' '[VARIABLE=VALUE1,VALUE2]' - check_matrix 'Config.Entrypoint' '[/bin/sh -c /ENTRYPOINT]' check_matrix 'Config.Cmd' '[COMMAND-OR-ARGS]' + check_matrix 'Config.Entrypoint' '[/bin/sh -c /ENTRYPOINT]' + check_matrix 'Config.Env' '[VARIABLE=VALUE1,VALUE2]' + check_matrix 'Config.ExposedPorts' 'map[12345:{}]' + check_matrix 'Config.Labels.exec' 'podman run -it --mount=type=bind,bind-propagation=Z,source=foo,destination=bar /script buz' + check_matrix 'Config.Labels.LABEL' 'VALUE' + check_matrix 'Config.StopSignal' 'SIGINT' + check_matrix 'Config.User' 'likes:things' check_matrix 'Config.Volumes' 'map[/VOLUME:{}]' check_matrix 'Config.WorkingDir' '/tmp' - check_matrix 'Config.Labels' '.*LABEL:VALUE' - check_matrix 'Config.Labels' '.*exec:podman run -it --mount=type=bind,bind-propagation=Z,source=foo,destination=bar /script buz' - check_matrix 'Config.StopSignal' 'SIGINT' buildah --debug=false inspect --type=image --format '{{(index .Docker.History 0).Comment}}' scratch-image-docker | grep PROBABLY-EMPTY buildah --debug=false inspect --type=image --format '{{(index .OCIv1.History 0).Comment}}' scratch-image-docker | grep PROBABLY-EMPTY @@ -182,10 +183,10 @@ function check_matrix() { buildah commit --format oci --signature-policy ${TESTSDIR}/policy.json $cid env-image-oci run_buildah --debug=false inspect --type=image --format '{{.Docker.Config.Env}}' env-image-docker - is "$output" ".*combined=bar/bar1" ".Docker.Config.Env" + expect_output --substring "combined=bar/bar1" run_buildah --debug=false inspect --type=image --format '{{.OCIv1.Config.Env}}' env-image-docker - is "$output" ".*combined=bar/bar1" ".OCIv1.Config.Env" + expect_output --substring "combined=bar/bar1" buildah rm $cid buildah rmi env-image-docker env-image-oci @@ -196,13 +197,13 @@ function check_matrix() { bndoutput=$(buildah --debug=false run $cid grep CapBnd /proc/self/status) buildah config --user 1000 $cid run_buildah --debug=false run $cid id -u - is "$output" "1000" "id -u in container" + expect_output "1000" run_buildah --debug=false run $cid sh -c "grep CapEff /proc/self/status | cut -f2" - is "$output" "0000000000000000" "CapEff in /proc/self/status" + expect_output "0000000000000000" run_buildah --debug=false run $cid grep CapBnd /proc/self/status - is "$output" "$bndoutput" "CapBnd in /proc/self/status" + expect_output "$bndoutput" buildah rm $cid } diff --git a/tests/from.bats b/tests/from.bats index 5f3ca47f9f4..a5301781bad 100644 --- a/tests/from.bats +++ b/tests/from.bats @@ -218,7 +218,7 @@ load helpers fi cid=$(buildah from --cpu-period=5000 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/cpu/cpu.cfs_period_us - is "$output" "5000" "cpu.cfs_period_us" + expect_output "5000" buildah rm $cid } @@ -231,7 +231,7 @@ load helpers fi cid=$(buildah from --cpu-quota=5000 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us - is "$output" "5000" "cpu.cfs_quota_us" + expect_output "5000" buildah rm $cid } @@ -244,7 +244,7 @@ load helpers fi cid=$(buildah from --cpu-shares=2 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/cpu/cpu.shares - is "$output" "1024" "cpu.shares" + expect_output "1024" buildah rm $cid } @@ -257,7 +257,7 @@ load helpers fi cid=$(buildah from --cpuset-cpus=0 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/cpuset/cpuset.cpus - is "$output" "0" "cpuset.cpus" + expect_output "0" buildah rm $cid } @@ -270,7 +270,7 @@ load helpers fi cid=$(buildah from --cpuset-mems=0 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/cpuset/cpuset.mems - is "$output" "0" "cpuset.mems" + expect_output "0" buildah rm $cid } @@ -283,7 +283,7 @@ load helpers fi cid=$(buildah from --memory=40m --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid cat /sys/fs/cgroup/memory/memory.limit_in_bytes - is "$output" "41943040" "memory.limit_in_bytes" + expect_output "41943040" buildah rm $cid } @@ -293,7 +293,7 @@ load helpers fi cid=$(buildah from --volume=${TESTDIR}:/myvol --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid -- cat /proc/mounts - is "$output" ".* /myvol " "/proc/mounts" + expect_output --substring " /myvol " buildah rm $cid } @@ -306,7 +306,7 @@ load helpers fi cid=$(buildah from --volume=${TESTDIR}:/myvol:ro --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid -- cat /proc/mounts - is "$output" ".* /myvol " "/proc/mounts" + expect_output --substring " /myvol " buildah rm $cid } @@ -319,7 +319,7 @@ load helpers fi cid=$(buildah from --shm-size=80m --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid -- df -h - is "$output" ".* 80.0M " "df -h" + expect_output --substring " 80.0M " buildah rm $cid } @@ -329,7 +329,7 @@ load helpers fi cid=$(buildah from --add-host=localhost:127.0.0.1 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah run $cid -- cat /etc/hosts - is "$output" ".*127.0.0.1 +localhost" "/etc/hosts" + expect_output --substring "127.0.0.1 +localhost" buildah rm $cid } diff --git a/tests/helpers.bash b/tests/helpers.bash index 9d503b25a2a..30cce390b7e 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -128,22 +128,49 @@ function die() { false } -######## -# is # Compare actual vs expected string; fail w/diagnostic if mismatch -######## +################### +# expect_output # Compare actual vs expected string; fail if mismatch +################### # -# Compares given string against expectations, using '=~' to allow patterns. +# Compares $output against the given string argument. Optional second +# argument is descriptive text to show as the error message (default: +# the command most recently run by 'run_buildah'). This text can be +# useful to isolate a failure when there are multiple identical +# run_buildah invocations, and the difference is solely in the +# config or setup; see, e.g., run.bats:run-cmd(). +# +# By default we run an exact string comparison; use --substring to +# look for the given string anywhere in $output. +# +# By default we look in "$output", which is set in run_buildah(). +# To override, use --from="some-other-string" (e.g. "${lines[0]}") # # Examples: # -# is "$actual" "$expected" "descriptive test name" -# is "apple" "orange" "name of a test that will fail in most universes" -# is "apple" "[a-z]\+" "this time it should pass" +# expect_output "this is exactly what we expect" +# expect_output "foo=bar" "description of this particular test" +# expect_output --from="${lines[0]}" "expected first line" # -function is() { - local actual="$1" - local expect="$2" - local testname="${3:-FIXME}" +function expect_output() { + # By default we examine $output, the result of run_buildah + local actual="$output" + local check_substring= + + # option processing: recognize --from="...", --substring + local opt + for opt; do + local value=$(expr "$opt" : '[^=]*=\(.*\)') + case "$opt" in + --from=*) actual="$value"; shift;; + --substring) check_substring=1; shift;; + --) shift; break;; + -*) die "Invalid option '$opt'" ;; + *) break;; + esac + done + + local expect="$1" + local testname="${2:-${MOST_RECENT_BUILDAH_COMMAND:-[no test name given]}}" if [ -z "$expect" ]; then if [ -z "$actual" ]; then @@ -152,8 +179,10 @@ function is() { expect='[no output]' elif [ "$actual" = "$expect" ]; then return - elif [[ "$actual" =~ ^$expect ]]; then - return + elif [ -n "$check_substring" ]; then + if [[ "$actual" =~ $expect ]]; then + return + fi fi # This is a multi-line message, which may in turn contain multi-line diff --git a/tests/images.bats b/tests/images.bats index 62224b7291b..08553ba1ec0 100644 --- a/tests/images.bats +++ b/tests/images.bats @@ -81,7 +81,7 @@ load helpers cid2=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json busybox) run_buildah --debug=false images -q --no-trunc expect_line_count 2 - is "${lines[0]}" ".*sha256" "images --no-trunc" + expect_output --substring --from="${lines[0]}" "sha256" buildah rm -a buildah rmi -a -f } @@ -135,7 +135,7 @@ load helpers @test "specify a nonexistent image" { run_buildah 1 --debug=false images alpine - is "${lines[0]}" "No such image alpine" "buildah images" + expect_output --from="${lines[0]}" "No such image alpine" expect_line_count 1 } @@ -147,11 +147,11 @@ load helpers expect_line_count 3 run_buildah --debug=false images --filter dangling=true - is "$output" ".* " "images ... dangling=true" + expect_output --substring " " expect_line_count 2 run_buildah --debug=false images --filter dangling=false - is "$output" ".* latest " "images ... dangling=false" + expect_output --substring " latest " expect_line_count 2 buildah rm -a diff --git a/tests/mount.bats b/tests/mount.bats index 36b68812c40..2df1b53578c 100644 --- a/tests/mount.bats +++ b/tests/mount.bats @@ -50,9 +50,9 @@ load helpers cid3=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) buildah mount "$cid3" run_buildah --debug=false mount - is "${lines[0]}" ".*/tmp" "mount line 1 of 3" - is "${lines[1]}" ".*/tmp" "mount line 2 of 3" - is "${lines[2]}" ".*/tmp" "mount line 3 of 3" + expect_output --from="${lines[0]}" --substring "/tmp" "mount line 1 of 3" + expect_output --from="${lines[1]}" --substring "/tmp" "mount line 2 of 3" + expect_output --from="${lines[2]}" --substring "/tmp" "mount line 3 of 3" expect_line_count 3 buildah rm --all diff --git a/tests/namespaces.bats b/tests/namespaces.bats index c02afeac77d..5549f7c99fa 100644 --- a/tests/namespaces.bats +++ b/tests/namespaces.bats @@ -188,21 +188,21 @@ load helpers run_buildah copy --chown 1:1 "$ctr" ${TESTDIR}/somefile / buildah run $RUNOPTS "$ctr" stat -c '%u:%g' /somefile run_buildah --debug=false run $RUNOPTS "$ctr" stat -c '%u:%g' /somefile - is "$output" "1:1" "stat /somefile" + expect_output "1:1" # Check that if we copy a directory into the container, its contents get the right permissions. run_buildah copy "$ctr" ${TESTDIR}/somedir /somedir buildah run $RUNOPTS "$ctr" stat -c '%u:%g' /somedir run_buildah --debug=false run $RUNOPTS "$ctr" stat -c '%u:%g' /somedir - is "$output" "0:0" "stat /somedir" + expect_output "0:0" run_buildah --debug=false mount "$ctr" mnt="$output" run stat -c '%u:%g %a' "$mnt"/somedir/someotherfile [ $status -eq 0 ] - is "$output" "$rootuid:$rootgid 4700" "stat from host" + expect_output "$rootuid:$rootgid 4700" buildah run $RUNOPTS "$ctr" stat -c '%u:%g %a' /somedir/someotherfile run_buildah --debug=false run $RUNOPTS "$ctr" stat -c '%u:%g %a' /somedir/someotherfile - is "$output" "0:0 4700" "stat inside container" + expect_output "0:0 4700" done } diff --git a/tests/pull.bats b/tests/pull.bats index e60eeb057de..81988255eff 100644 --- a/tests/pull.bats +++ b/tests/pull.bats @@ -15,7 +15,7 @@ load helpers @test "pull-blocked" { run_buildah 1 --registries-conf ${TESTSDIR}/registries.conf.block pull --signature-policy ${TESTSDIR}/policy.json docker.io/alpine - is "$output" ".*is blocked by configuration" "sdfsdfsdf FIXME" + expect_output --substring "is blocked by configuration" run_buildah --registries-conf ${TESTSDIR}/registries.conf pull --signature-policy ${TESTSDIR}/policy.json docker.io/alpine } @@ -24,17 +24,17 @@ load helpers run_buildah pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json busybox:glibc run_buildah pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json busybox run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*busybox:glibc" "'buildah images' includes busybox:glibc" - is "$output" ".*busybox:latest" "'buildah images' includes busybox:latest" + expect_output --substring "busybox:glibc" + expect_output --substring "busybox:latest" run_buildah pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json quay.io/libpod/alpine_nginx:latest run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine_nginx:latest" "pulled alpine_nginx:latest" + expect_output --substring "alpine_nginx:latest" run_buildah rmi quay.io/libpod/alpine_nginx:latest run_buildah pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json quay.io/libpod/alpine_nginx run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine_nginx:latest" "rmi'ed then re-pulled alpine_nginx" + expect_output --substring "alpine_nginx:latest" run_buildah pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json alpine@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe run_buildah 1 pull --registries-conf ${TESTSDIR}/registries.conf --signature-policy ${TESTSDIR}/policy.json fakeimage/fortest @@ -48,7 +48,7 @@ load helpers run_buildah rmi alpine run_buildah pull --signature-policy ${TESTSDIR}/policy.json docker-archive:${TESTDIR}/alp.tar run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine" "buildah images" + expect_output --substring "alpine" run_buildah 1 pull --all-tags --signature-policy ${TESTSDIR}/policy.json docker-archive:${TESTDIR}/alp.tar run rm -rf ${TESTDIR}/alp.tar echo "$output" @@ -61,7 +61,7 @@ load helpers run_buildah rmi alpine run_buildah pull --signature-policy ${TESTSDIR}/policy.json oci-archive:${TESTDIR}/alp.tar run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine" "buildah images" + expect_output --substring "alpine" run_buildah 1 pull --all-tags --signature-policy ${TESTSDIR}/policy.json oci-archive:${TESTDIR}/alp.tar run rm -rf ${TESTDIR}/alp.tar echo "$output" @@ -75,7 +75,7 @@ load helpers run_buildah rmi alpine run_buildah pull --signature-policy ${TESTSDIR}/policy.json dir:${TESTDIR}/buildahtest run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*buildahtest" "buildah images" + expect_output --substring "buildahtest" run_buildah 1 pull --all-tags --signature-policy ${TESTSDIR}/policy.json dir:${TESTDIR}/buildahtest run rm -rf ${TESTDIR}/buildahtest echo "$output" @@ -97,7 +97,7 @@ load helpers [ "$status" -eq 0 ] run_buildah pull --signature-policy ${TESTSDIR}/policy.json docker-daemon:docker.io/library/alpine:latest run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine:latest" "buildah images" + expect_output --substring "alpine:latest" run_buildah rmi alpine run_buildah 1 pull --all-tags --signature-policy ${TESTSDIR}/policy.json docker-daemon:docker.io/library/alpine:latest run docker rmi -f alpine:latest @@ -121,13 +121,13 @@ load helpers run_buildah rmi alpine run_buildah pull --signature-policy ${TESTSDIR}/policy.json ostree:alpine@${TESTDIR}/ostree-repo run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*ostree-repo:latest" "buildah images" + expect_output --substring "ostree-repo:latest" } @test "pull-all-tags" { run_buildah pull --signature-policy ${TESTSDIR}/policy.json --all-tags alpine - is "$output" ".*alpine:latest" "buildah pull" + expect_output --substring "alpine:latest" run_buildah images -q [ $(wc -l <<< "$output") -ge 3 ] @@ -139,7 +139,7 @@ load helpers run_buildah rmi alpine run_buildah pull --signature-policy ${TESTSDIR}/policy.json oci:${TESTDIR}/alpine run_buildah images --format "{{.Name}}:{{.Tag}}" - is "$output" ".*alpine" "buildah images" + expect_output --substring "alpine" run_buildah 1 pull --all-tags --signature-policy ${TESTSDIR}/policy.json oci:${TESTDIR}/alpine run rm -rf ${TESTDIR}/alpine echo "$output" diff --git a/tests/push.bats b/tests/push.bats index ebdbad1d6a0..0ea941cc783 100644 --- a/tests/push.bats +++ b/tests/push.bats @@ -65,6 +65,6 @@ load helpers @test "push without destination" { buildah pull --signature-policy ${TESTSDIR}/policy.json busybox run_buildah 1 push --signature-policy ${TESTSDIR}/policy.json busybox - is "$output" ".*docker://busybox" "output of buildah push" + expect_output --substring "docker://busybox" buildah rmi busybox } diff --git a/tests/registries.bats b/tests/registries.bats index 55cd03188b6..b1d00e219a9 100644 --- a/tests/registries.bats +++ b/tests/registries.bats @@ -27,7 +27,7 @@ load helpers run_buildah --debug=false inspect -f "{{.FromImageID}}" $cid expect_line_count 1 if [ "$lastid" != "" ] ; then - is "$output" "$lastid" ".FromImageId" + expect_output "$lastid" fi lastid="$output" done diff --git a/tests/rename.bats b/tests/rename.bats index 016ed0598e2..9ba5e28783a 100644 --- a/tests/rename.bats +++ b/tests/rename.bats @@ -9,10 +9,10 @@ load helpers buildah rename ${cid} ${new_name} run_buildah containers --format "{{.ContainerName}}" - is "$output" ".*test-container" "buildah containers" + expect_output --substring "test-container" run_buildah --debug=false containers --quiet -f name=${old_name} - is "$output" "" "old_name no longer in buildah containers" + expect_output "" buildah rm ${new_name} [ "$status" -eq 0 ] @@ -21,7 +21,7 @@ load helpers @test "rename same name as current name" { cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah 1 --debug=false rename ${cid} ${cid} - is "$output" 'renaming a container with the same name as its current name' "output of buildah rename" + expect_output 'renaming a container with the same name as its current name' buildah rm $cid buildah rmi -f alpine @@ -31,7 +31,7 @@ load helpers cid1=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) cid2=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json busybox) run_buildah 1 --debug=false rename ${cid1} ${cid2} - is "$output" ".* already in use by " "output of buildah rename" + expect_output --substring " already in use by " buildah rm $cid1 $cid2 buildah rmi -f alpine busybox diff --git a/tests/rm.bats b/tests/rm.bats index 1b2f7187cb4..3d61a1d9593 100644 --- a/tests/rm.bats +++ b/tests/rm.bats @@ -12,9 +12,9 @@ load helpers @test "remove multiple containers errors" { run_buildah 1 --debug=false rm mycontainer1 mycontainer2 mycontainer3 - is "${lines[0]}" "error removing container \"mycontainer1\": error reading build container: container not known" "output line 1" - is "${lines[1]}" "error removing container \"mycontainer2\": error reading build container: container not known" "output line 2" - is "${lines[2]}" "error removing container \"mycontainer3\": error reading build container: container not known" "output line 3" + expect_output --from="${lines[0]}" "error removing container \"mycontainer1\": error reading build container: container not known" "output line 1" + expect_output --from="${lines[1]}" "error removing container \"mycontainer2\": error reading build container: container not known" "output line 2" + expect_output --from="${lines[2]}" "error removing container \"mycontainer3\": error reading build container: container not known" "output line 3" expect_line_count 3 } @@ -42,7 +42,7 @@ load helpers @test "use conflicting commands to remove containers" { cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah 1 --debug=false rm -a "$cid" - is "$output" ".*when using the --all switch, you may not pass any containers names or IDs" "output from buildah rm -a cid" + expect_output --substring "when using the --all switch, you may not pass any containers names or IDs" run_buildah rm "$cid" run_buildah rmi alpine } diff --git a/tests/rmi.bats b/tests/rmi.bats index 99580dfec99..f713ed33705 100644 --- a/tests/rmi.bats +++ b/tests/rmi.bats @@ -18,7 +18,7 @@ load helpers buildah rm "$cid" buildah rmi alpine run_buildah --debug=false images -q - is "$output" "" "images -q" + expect_output "" } @test "remove multiple images" { @@ -30,14 +30,14 @@ load helpers buildah rmi -f alpine busybox run_buildah --debug=false images -q - is "$output" "" "images -q" + expect_output "" } @test "remove multiple non-existent images errors" { run_buildah 1 --debug=false rmi image1 image2 image3 - is "${lines[0]}" "could not get image \"image1\": identifier is not an image" "output line 1" - is "${lines[1]}" "could not get image \"image2\": identifier is not an image" "output line 2" - is "${lines[2]}" "could not get image \"image3\": identifier is not an image" "output line 3" + expect_output --from="${lines[0]}" "could not get image \"image1\": identifier is not an image" "output line 1" + expect_output --from="${lines[1]}" "could not get image \"image2\": identifier is not an image" "output line 2" + expect_output --from="${lines[2]}" "could not get image \"image3\": identifier is not an image" "output line 3" [ $(wc -l <<< "$output") -gt 2 ] } @@ -47,7 +47,7 @@ load helpers cid3=$(buildah from --signature-policy ${TESTSDIR}/policy.json busybox) buildah rmi -a -f run_buildah --debug=false images -q - is "$output" "" "images -q" + expect_output "" cid1=$(buildah from --signature-policy ${TESTSDIR}/policy.json scratch) cid2=$(buildah from --signature-policy ${TESTSDIR}/policy.json alpine) @@ -58,7 +58,7 @@ load helpers buildah rmi --all --force run_buildah --debug=false images -q - is "$output" "" "images -q" + expect_output "" } @test "use prune to remove dangling images" { @@ -93,24 +93,24 @@ load helpers buildah rmi --all --force run_buildah --debug=false images -q - is "$output" "" "images -q" + expect_output "" } @test "use conflicting commands to remove images" { cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) buildah rm "$cid" run_buildah 1 --debug=false rmi -a alpine - is "$output" ".*when using the --all switch, you may not pass any images names or IDs" "rmi -a with name" + expect_output --substring "when using the --all switch, you may not pass any images names or IDs" cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) buildah rm "$cid" run_buildah 1 --debug=false rmi -p alpine - is "$output" ".*when using the --prune switch, you may not pass any images names or IDs" "rmi -p with name" + expect_output --substring "when using the --prune switch, you may not pass any images names or IDs" cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) buildah rm "$cid" run_buildah 1 --debug=false rmi -a -p - is "$output" ".*when using the --all switch, you may not use --prune switch" "rmi -a -p" + expect_output --substring "when using the --all switch, you may not use --prune switch" buildah rmi --all } @@ -150,7 +150,7 @@ load helpers expect_line_count 2 run_buildah --debug=false rmi test3 run_buildah --debug=false images -a -q - is "$output" "" "images -a -q" + expect_output "" } @test "rmi image that is created from another named image" { diff --git a/tests/run.bats b/tests/run.bats index 702dc31a383..02fcbdfaa1b 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -12,10 +12,10 @@ load helpers root=$(buildah mount $cid) buildah config --workingdir /tmp $cid run_buildah --debug=false run $cid pwd - is "$output" "/tmp" "pwd" + expect_output "/tmp" buildah config --workingdir /root $cid run_buildah --debug=false run $cid pwd - is "$output" "/root" "pwd" + expect_output "/root" cp ${TESTDIR}/randomfile $root/tmp/ buildah run $cid cp /tmp/randomfile /tmp/other-randomfile test -s $root/tmp/other-randomfile @@ -36,19 +36,19 @@ load helpers # This should succeed, because buildah run stops caring at the --, which is preserved as part of the command. run_buildah --debug=false run $cid echo -- -n test - is "$output" "-- -n test" "echo" + expect_output -- "-- -n test" # This should succeed, because buildah run stops caring at the --, which is not part of the command. run_buildah --debug=false run $cid -- echo -n -- test - is "$output" "-- test" "echo" + expect_output -- "-- test" # This should succeed, because buildah run stops caring at the --. run_buildah --debug=false run $cid -- echo -- -n test -- - is "$output" "-- -n test --" "echo" + expect_output -- "-- -n test --" # This should succeed, because buildah run stops caring at the --. run_buildah --debug=false run $cid -- echo -n "test" - is "$output" "test" "echo" + expect_output "test" buildah rm $cid } @@ -67,57 +67,57 @@ load helpers buildah config --entrypoint "" $cid buildah config --cmd pwd $cid run_buildah 1 --debug=false run $cid - is "$output" ".*command must be specified" "empty entrypoint, cmd, no args" + expect_output --substring "command must be specified" "empty entrypoint, cmd, no args" # empty entrypoint, configured cmd, empty run arguments, end parsing option buildah config --entrypoint "" $cid buildah config --cmd pwd $cid run_buildah 1 --debug=false run $cid -- - is "$output" ".*command must be specified" "empty entrypoint, cmd, no args, --" + expect_output --substring "command must be specified" "empty entrypoint, cmd, no args, --" # configured entrypoint, empty cmd, empty run arguments buildah config --entrypoint pwd $cid buildah config --cmd "" $cid run_buildah 1 --debug=false run $cid - is "$output" ".*command must be specified" "entrypoint, empty cmd, no args" + expect_output --substring "command must be specified" "entrypoint, empty cmd, no args" # configured entrypoint, empty cmd, empty run arguments, end parsing option buildah config --entrypoint pwd $cid buildah config --cmd "" $cid run_buildah 1 --debug=false run $cid -- - is "$output" ".*command must be specified" "entrypoint, empty cmd, no args, --" + expect_output --substring "command must be specified" "entrypoint, empty cmd, no args, --" # configured entrypoint only, empty run arguments buildah config --entrypoint pwd $cid run_buildah 1 --debug=false run $cid - is "$output" ".*command must be specified" "entrypoint, no args" + expect_output --substring "command must be specified" "entrypoint, no args" # configured entrypoint only, empty run arguments, end parsing option buildah config --entrypoint pwd $cid run_buildah 1 --debug=false run $cid -- - is "$output" ".*command must be specified" "entrypoint, no args, --" + expect_output --substring "command must be specified" "entrypoint, no args, --" # cofigured cmd only, empty run arguments buildah config --cmd pwd $cid run_buildah 1 --debug=false run $cid - is "$output" ".*command must be specified" "cmd, no args" + expect_output --substring "command must be specified" "cmd, no args" # configured cmd only, empty run arguments, end parsing option buildah config --cmd pwd $cid run_buildah 1 --debug=false run $cid -- - is "$output" ".*command must be specified" "cmd, no args, --" + expect_output --substring "command must be specified" "cmd, no args, --" # configured entrypoint, configured cmd, empty run arguments buildah config --entrypoint "pwd" $cid buildah config --cmd "whoami" $cid run_buildah 1 --debug=false run $cid - is "$output" ".*command must be specified" "entrypoint, cmd, no args" + expect_output --substring "command must be specified" "entrypoint, cmd, no args" # configured entrypoint, configured cmd, empty run arguments, end parsing option buildah config --entrypoint "pwd" $cid buildah config --cmd "whoami" $cid run_buildah 1 --debug=false run $cid -- - is "$output" ".*command must be specified" "entrypoint, cmd, no args" + expect_output --substring "command must be specified" "entrypoint, cmd, no args" # Configured entrypoint/cmd shouldn't modify behaviour of run with argument @@ -127,29 +127,29 @@ load helpers buildah config --entrypoint "" $cid buildah config --cmd "/invalid/cmd" $cid run_buildah --debug=false run $cid -- pwd - is "$output" "/tmp" "empty entrypoint, invalid cmd, pwd" + expect_output "/tmp" "empty entrypoint, invalid cmd, pwd" # configured entrypoint, empty cmd, configured run arguments buildah config --entrypoint "/invalid/entrypoint" $cid buildah config --cmd "" $cid run_buildah --debug=false run $cid -- pwd - is "$output" "/tmp" "invalid entrypoint, empty cmd, pwd" + expect_output "/tmp" "invalid entrypoint, empty cmd, pwd" # configured entrypoint only, configured run arguments buildah config --entrypoint "/invalid/entrypoint" $cid run_buildah --debug=false run $cid -- pwd - is "$output" "/tmp" "invalid entrypoint, no cmd(??), pwd" + expect_output "/tmp" "invalid entrypoint, no cmd(??), pwd" # cofigured cmd only, configured run arguments buildah config --cmd "/invalid/cmd" $cid run_buildah --debug=false run $cid -- pwd - is "$output" "/tmp" "invalid cmd, no entrypoint(??), pwd" + expect_output "/tmp" "invalid cmd, no entrypoint(??), pwd" # configured entrypoint, configured cmd, configured run arguments buildah config --entrypoint "/invalid/entrypoint" $cid buildah config --cmd "/invalid/cmd" $cid run_buildah --debug=false run $cid -- pwd - is "$output" "/tmp" "invalid cmd & entrypoint, pwd" + expect_output "/tmp" "invalid cmd & entrypoint, pwd" buildah rm $cid } @@ -161,10 +161,10 @@ function configure_and_check_user() { run_buildah config -u "$setting" $cid run_buildah --debug=false run -- $cid id -u - is "$output" "$expect_u" "id -u ($setting)" + expect_output "$expect_u" "id -u ($setting)" run_buildah --debug=false run -- $cid id -g - is "$output" "$expect_g" "id -g ($setting)" + expect_output "$expect_g" "id -g ($setting)" } @test "run-user" { @@ -201,15 +201,15 @@ function configure_and_check_user() { buildah config -u ${testbogususer} $cid run_buildah 1 --debug=false run -- $cid id -u - is "$output" ".*unknown user" "id -u (bogus user)" + expect_output --substring "unknown user" "id -u (bogus user)" run_buildah 1 --debug=false run -- $cid id -g - is "$output" ".*unknown user" "id -g (bogus user)" + expect_output --substring "unknown user" "id -g (bogus user)" ln -vsf /etc/passwd $root/etc/passwd buildah config -u ${testuser}:${testgroup} $cid run_buildah 1 --debug=false run -- $cid id -u echo "$output" - is "$output" ".*unknown user" "run as unknown user" + expect_output --substring "unknown user" "run as unknown user" buildah unmount $cid buildah rm $cid @@ -227,7 +227,7 @@ function configure_and_check_user() { run_buildah --debug=false run $cid hostname [ "$output" != "foobar" ] run_buildah --debug=false run --hostname foobar $cid hostname - is "$output" "foobar" "hostname" + expect_output "foobar" buildah rm $cid } @@ -298,23 +298,23 @@ function configure_and_check_user() { fi cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid awk '/open files/{print $4}' /proc/self/limits - is "$output" "1048576" "limits: open files (unlimited)" + expect_output "1048576" "limits: open files (unlimited)" run_buildah --debug=false run $cid awk '/processes/{print $3}' /proc/self/limits - is "$output" "1048576" "limits: processes (unlimited)" + expect_output "1048576" "limits: processes (unlimited)" buildah rm $cid cid=$(buildah from --ulimit nofile=300:400 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid awk '/open files/{print $4}' /proc/self/limits - is "$output" "300" "limits: open files (w/file limit)" + expect_output "300" "limits: open files (w/file limit)" run_buildah --debug=false run $cid awk '/processes/{print $3}' /proc/self/limits - is "$output" "1048576" "limits: processes (w/file limit)" + expect_output "1048576" "limits: processes (w/file limit)" buildah rm $cid cid=$(buildah from --ulimit nproc=100:200 --ulimit nofile=300:400 --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid awk '/open files/{print $4}' /proc/self/limits - is "$output" "300" "limits: open files (w/file & proc limits)" + expect_output "300" "limits: open files (w/file & proc limits)" run_buildah --debug=false run $cid awk '/processes/{print $3}' /proc/self/limits - is "$output" "100" "limits: processes (w/file & proc limits)" + expect_output "100" "limits: processes (w/file & proc limits)" buildah rm $cid } @@ -329,7 +329,7 @@ function configure_and_check_user() { [ "$status" -ne 0 ] # We'll create the mountpoint for "run". run_buildah --debug=false run $cid ls -1 /var/lib - is "$output" ".*registry" "ls /var/lib" + expect_output --substring "registry" # Double-check that the mountpoint is there. test -d "$mnt"/var/lib/registry diff --git a/tests/secrets.bats b/tests/secrets.bats index 769328deb2b..4506003f83e 100644 --- a/tests/secrets.bats +++ b/tests/secrets.bats @@ -29,9 +29,9 @@ function teardown() { runc --version cid=$(buildah --default-mounts-file "$MOUNTS_PATH" --debug=false from --pull --signature-policy ${TESTSDIR}/policy.json alpine) run_buildah --debug=false run $cid ls /run/secrets - is "$output" ".*test.txt" "ls /run/secrets" + expect_output --substring "test.txt" run_buildah --debug run $cid ls /run/secrets/mysymlink - is "$output" ".*key.pem" "ls /run/secrets/mysymlink" + expect_output --substring "key.pem" buildah rm $cid rm -rf $TESTSDIR/containers rm -rf $TESTSDIR/rhel diff --git a/tests/selinux.bats b/tests/selinux.bats index 4d499e3476f..2ebe5ec4965 100644 --- a/tests/selinux.bats +++ b/tests/selinux.bats @@ -19,7 +19,7 @@ load helpers # Ensure that we label the same container consistently across multiple "run" instructions. run_buildah --debug=false run $cid sh -c 'tr \\0 \\n < /proc/self/attr/current' - is "$output" "$firstlabel" "label of second container == first" + expect_output "$firstlabel" "label of second container == first" # Ensure that different containers get different labels. cid1=$(buildah --debug=false from --quiet --signature-policy ${TESTSDIR}/policy.json $image) @@ -46,7 +46,7 @@ load helpers # Create a container and read its context as a baseline. cid=$(buildah --debug=false from --security-opt label=disable --quiet --signature-policy ${TESTSDIR}/policy.json $image) run_buildah --debug=false run $cid sh -c 'tr \\0 \\n < /proc/self/attr/current' - is "$output" "$firstlabel" "container context matches our own" + expect_output "$firstlabel" "container context matches our own" } @test "selinux specific level" { @@ -64,9 +64,9 @@ load helpers # Inspect image run_buildah --debug=false inspect --format '{{.ProcessLabel}}' $cid - is "$output" $firstlabel "buildah inspect" + expect_output "$firstlabel" # Check actual running context run_buildah --debug=false run $cid sh -c 'tr \\0 \\n < /proc/self/attr/current' - is "$output" "$firstlabel" "running container context" + expect_output "$firstlabel" "running container context" } diff --git a/tests/squash.bats b/tests/squash.bats index 6f578c9d2b6..c938111adda 100644 --- a/tests/squash.bats +++ b/tests/squash.bats @@ -7,10 +7,11 @@ function check_lengths() { local image=$1 local expect=$2 + # matrix test: check given .Docker.* and .OCIv1.* fields in image for which in Docker OCIv1; do for field in RootFS.DiffIDs History; do run_buildah --debug=false inspect -t image -f "{{len .$which.$field}}" $image - is "$output" "$expect" "len(.$which.$field) ($image)" + expect_output "$expect" done done }