Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[release-1.35] integration test: handle new labels in "bud and test --unsetlabel" #5503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2251,24 +2251,32 @@ _EOF
}

@test "bud and test --unsetlabel" {
_prefetch registry.fedoraproject.org/fedora-minimal
base=registry.fedoraproject.org/fedora-minimal
_prefetch $base
target=exp

run_buildah --version
local -a output_fields=($output)
buildah_version=${output_fields[2]}
run_buildah build $WITH_POLICY_JSON -t exp -f $BUDFILES/base-with-labels/Containerfile

run_buildah inspect --format '{{ index .Docker.Config.Labels "license"}}' exp
expect_output "MIT" "license must be MIT from fedora base image"
run_buildah inspect --format '{{ index .Docker.Config.Labels "name"}}' exp
expect_output "fedora" "name must be fedora from base image"
run_buildah inspect --format '{{ index .Docker.Config.Labels "vendor"}}' exp
expect_output "Fedora Project" "vendor must be fedora from base image"
buildah inspect --format '{{ .Docker.Config.Labels }}' $base
not_want_output='map[]'
assert "$output" != "$not_want_output" "expected some labels to be set in base image $base"

labels=$(buildah inspect --format '{{ range $key, $value := .Docker.Config.Labels }}{{ $key }} {{end}}' $base)
labelflags="--label hello=world"
for label in $labels; do
if test $label != io.buildah.version ; then
labelflags="$labelflags --unsetlabel $label"
fi
done

run_buildah build $WITH_POLICY_JSON $labelflags -t $target --from $base $BUDFILES/base-with-labels

run_buildah build $WITH_POLICY_JSON --unsetlabel license --unsetlabel name --unsetlabel vendor --unsetlabel version --label hello=world -t exp -f $BUDFILES/base-with-labels/Containerfile
# no labels should be inherited from base image only the, buildah version label
# no labels should be inherited from base image, only the buildah version label
# and `hello=world` which we just added using cli flag
want_output='map["hello":"world" "io.buildah.version":"'$buildah_version'"]'
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' exp
run_buildah inspect --format '{{printf "%q" .Docker.Config.Labels}}' $target
expect_output "$want_output"
}

Expand Down
9 changes: 5 additions & 4 deletions tests/config.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ function check_matrix() {
}

@test "config --unsetlabel" {
_prefetch registry.fedoraproject.org/fedora-minimal
run_buildah from --quiet --pull=false $WITH_POLICY_JSON registry.fedoraproject.org/fedora-minimal
base=registry.fedoraproject.org/fedora-minimal
_prefetch $base
run_buildah from --quiet --pull=false $WITH_POLICY_JSON $base
cid=$output
run_buildah commit $WITH_POLICY_JSON $cid with-name-label
run_buildah config --unsetlabel name $cid
run_buildah commit $WITH_POLICY_JSON $cid without-name-label

run_buildah inspect --format '{{ index .Docker.Config.Labels "name"}}' with-name-label
expect_output "fedora" "name label should be set with value as fedora"
assert "$output" != "" "label should be set in base image"
run_buildah inspect --format '{{ index .Docker.Config.Labels "name"}}' without-name-label
expect_output "" "name label should be removed"
assert "$output" == "" "name label should be removed"
}

@test "config set empty entrypoint doesn't wipe cmd" {
Expand Down