buildah/tests/version.bats

53 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bats
load helpers
@test "buildah version test" {
BATS tests - extensive but minor cleanup This started off as bug fixes necessary to get BATS tests actually working on RHEL8 (they weren't). It grew. I will defend my actions in the first comment post. Primary change: import some helpers from podman BATS tests, most importantly 'run_buildah' and 'is'. The vast majority of the changes you'll see here are of the form: - run buildah ... - [ $status = 0 ] - [ check $output ] + run_buildah ... ! automatically checks status + is "$output" "..." Also: chmod'ed some files -x. Necessary because rpmbuild tries to be oh-so-clever about requirements, and when it sees an executable file with a shebang line like '#!env bats' it helpfully adds 'Requires: /usr/bin/bats' to the rpm, which then fails to install because RHEL8 does not have bats. Also: refactored duplicate code in a few places, by writing and invoking module-specific helper functions. Also: changed a handful of 'buildah's to run_buildah, in order to get error checking and debug logging. Also: added descriptive reasons to many "skip"s. Also: selinux test: some tweakery to make it run on production system (context is different if /usr/bin/buildah is chcon'ed appropriately). I can't get this test to pass on Fedora from a build dir, and I'm actually not convinced that this test has ever passed, but let's see what CI shows. Also: selinux test: skip broken test (#1465). Also: version test: skip parts of it if running w/o sources. Tests are now passing as root on RHEL8; rootless has numerous failures which I don't believe are related to this PR. Signed-off-by: Ed Santiago <santiago@redhat.com> Closes: #1472 Approved by: TomSweeneyRedHat
2019-04-02 05:56:29 +08:00
run_buildah version
}
@test "buildah version current in .spec file Version" {
if [ ! -d "${TEST_SOURCES}/../contrib/rpm" ]; then
BATS tests - extensive but minor cleanup This started off as bug fixes necessary to get BATS tests actually working on RHEL8 (they weren't). It grew. I will defend my actions in the first comment post. Primary change: import some helpers from podman BATS tests, most importantly 'run_buildah' and 'is'. The vast majority of the changes you'll see here are of the form: - run buildah ... - [ $status = 0 ] - [ check $output ] + run_buildah ... ! automatically checks status + is "$output" "..." Also: chmod'ed some files -x. Necessary because rpmbuild tries to be oh-so-clever about requirements, and when it sees an executable file with a shebang line like '#!env bats' it helpfully adds 'Requires: /usr/bin/bats' to the rpm, which then fails to install because RHEL8 does not have bats. Also: refactored duplicate code in a few places, by writing and invoking module-specific helper functions. Also: changed a handful of 'buildah's to run_buildah, in order to get error checking and debug logging. Also: added descriptive reasons to many "skip"s. Also: selinux test: some tweakery to make it run on production system (context is different if /usr/bin/buildah is chcon'ed appropriately). I can't get this test to pass on Fedora from a build dir, and I'm actually not convinced that this test has ever passed, but let's see what CI shows. Also: selinux test: skip broken test (#1465). Also: version test: skip parts of it if running w/o sources. Tests are now passing as root on RHEL8; rootless has numerous failures which I don't believe are related to this PR. Signed-off-by: Ed Santiago <santiago@redhat.com> Closes: #1472 Approved by: TomSweeneyRedHat
2019-04-02 05:56:29 +08:00
skip "No source dir available"
fi
run_buildah version
bversion=$(awk '/^Version:/ { print $NF }' <<< "$output")
rversion=$(awk '/^Version:/ { print $NF }' < ${TEST_SOURCES}/../contrib/rpm/buildah.spec)
echo "bversion=${bversion}"
echo "rversion=${rversion}"
test "${bversion}" = "${rversion}" -o "${bversion}" = "${rversion}-dev"
}
@test "buildah version current in .spec file changelog" {
if [ ! -d "${TEST_SOURCES}/../contrib/rpm" ]; then
BATS tests - extensive but minor cleanup This started off as bug fixes necessary to get BATS tests actually working on RHEL8 (they weren't). It grew. I will defend my actions in the first comment post. Primary change: import some helpers from podman BATS tests, most importantly 'run_buildah' and 'is'. The vast majority of the changes you'll see here are of the form: - run buildah ... - [ $status = 0 ] - [ check $output ] + run_buildah ... ! automatically checks status + is "$output" "..." Also: chmod'ed some files -x. Necessary because rpmbuild tries to be oh-so-clever about requirements, and when it sees an executable file with a shebang line like '#!env bats' it helpfully adds 'Requires: /usr/bin/bats' to the rpm, which then fails to install because RHEL8 does not have bats. Also: refactored duplicate code in a few places, by writing and invoking module-specific helper functions. Also: changed a handful of 'buildah's to run_buildah, in order to get error checking and debug logging. Also: added descriptive reasons to many "skip"s. Also: selinux test: some tweakery to make it run on production system (context is different if /usr/bin/buildah is chcon'ed appropriately). I can't get this test to pass on Fedora from a build dir, and I'm actually not convinced that this test has ever passed, but let's see what CI shows. Also: selinux test: skip broken test (#1465). Also: version test: skip parts of it if running w/o sources. Tests are now passing as root on RHEL8; rootless has numerous failures which I don't believe are related to this PR. Signed-off-by: Ed Santiago <santiago@redhat.com> Closes: #1472 Approved by: TomSweeneyRedHat
2019-04-02 05:56:29 +08:00
skip "No source dir available"
fi
run_buildah version
bversion=$(awk '/^Version:/ { print $NF }' <<< "$output")
grep -A1 ^%changelog ${TEST_SOURCES}/../contrib/rpm/buildah.spec | grep -q " ${bversion}-"
}
@test "buildah version current in package" {
if [ -n "$(command -v rpm)" ]; then
run rpm -qfi ${BUILDAH_BINARY}
[ $status -eq 0 ] || skip "buildah binary is not owned by package"
rversion=$(awk '/^Version/ { print $NF }' <<< "$output")
elif [ -n "$(command -v dpkg)" ]; then
run dpkg --search ${BUILDAH_BINARY}
[ $status -eq 0 ] || skip "buildah binary is not owned by package"
package=$(awk -F : '{ print $1 }' <<< "${output}")
run dpkg --status $package
[ $status -eq 0 ] || skip "buildah binary is not owned by package"
rversion=$(awk '/^Version/ { print $NF }' <<< "$output")
rversion=${rversion%%-*}
else
skip "No supported package manager"
fi
run_buildah version
bversion=$(awk '/^Version:/ { print $NF }' <<< "$output")
echo "bversion=${bversion}"
echo "rversion=${rversion}"
test "${bversion}" = "${rversion}" -o "${bversion}" = "${rversion}-dev"
}