diff --git a/testing/bats/helpers/test-helpers.bash b/testing/bats/helpers/test-helpers.bash index 9126fe53..b68c31f9 100644 --- a/testing/bats/helpers/test-helpers.bash +++ b/testing/bats/helpers/test-helpers.bash @@ -25,6 +25,12 @@ function skipIfNotLinux() { fi } +function skipIfPackageNotInstalled() { + if [[ "${FLUENTDO_AGENT_PACKAGE_INSTALLED:-}" != "true" ]]; then + skip 'Skipping test: package not installed' + fi +} + function skipIfCentos6() { if [[ -f /etc/redhat-release ]] && grep -qi "centos.*6" /etc/redhat-release; then skip 'Skipping test: detected CentOS 6' diff --git a/testing/bats/run-package-functional-tests.sh b/testing/bats/run-package-functional-tests.sh index 35ec4883..91c36e3f 100755 --- a/testing/bats/run-package-functional-tests.sh +++ b/testing/bats/run-package-functional-tests.sh @@ -77,6 +77,7 @@ echo "INFO: running test container 'bats/test/$DISTRO'" "${CONTAINER_RUNTIME}" run --rm -t \ -v "$DOWNLOAD_DIR:/downloads:ro" \ -e FLUENT_BIT_BINARY="$FLUENT_BIT_BINARY" \ + -e FLUENTDO_AGENT_PACKAGE_INSTALLED=true \ "bats/test/$DISTRO" echo "INFO: All tests complete" diff --git a/testing/bats/tests/functional/linux/verify-deb.bats b/testing/bats/tests/functional/linux/verify-deb.bats index a665f983..987df111 100644 --- a/testing/bats/tests/functional/linux/verify-deb.bats +++ b/testing/bats/tests/functional/linux/verify-deb.bats @@ -11,20 +11,21 @@ load "$BATS_FILE_ROOT/load.bash" setup() { skipIfNotLinux + skipIfPackageNotInstalled if ! command -v dpkg &> /dev/null; then skip "Skipping test: no dpkg command" fi export PACKAGE_NAME="fluentdo-agent" - if ! dpkg -s "$PACKAGE_NAME" ; then - skip "Skipping test: $PACKAGE_NAME DEB not installed" - fi } teardown() { if [[ -n "${SKIP_TEARDOWN:-}" ]]; then echo "Skipping teardown" fi + if command -v dpkg &> /dev/null; then + run dpkg -l + fi } @test "DEB package is installed" { diff --git a/testing/bats/tests/functional/linux/verify-files.bats b/testing/bats/tests/functional/linux/verify-files.bats index 224dfb07..9ae6608b 100644 --- a/testing/bats/tests/functional/linux/verify-files.bats +++ b/testing/bats/tests/functional/linux/verify-files.bats @@ -15,21 +15,19 @@ setup() { export PACKAGE_NAME="fluentdo-agent" # Ensure we skip tests in the container - if command -v rpm &>/dev/null; then - if ! rpm -qa | grep -q "$PACKAGE_NAME" ; then - skip "Skipping test: $PACKAGE_NAME RPM not installed" - fi - elif command -v dpkg &>/dev/null; then - if ! dpkg -s "$PACKAGE_NAME" ; then - skip "Skipping test: $PACKAGE_NAME DEB not installed" - fi - fi + skipIfPackageNotInstalled } teardown() { if [[ -n "${SKIP_TEARDOWN:-}" ]]; then echo "Skipping teardown" fi + if command -v rpm &> /dev/null; then + run rpm -qa + fi + if command -v dpkg &> /dev/null; then + run dpkg -l + fi } # Packages should be structured like so: diff --git a/testing/bats/tests/functional/linux/verify-rpm.bats b/testing/bats/tests/functional/linux/verify-rpm.bats index 7f2c12de..567882a4 100644 --- a/testing/bats/tests/functional/linux/verify-rpm.bats +++ b/testing/bats/tests/functional/linux/verify-rpm.bats @@ -10,15 +10,13 @@ load "$BATS_FILE_ROOT/load.bash" # bats file_tags=functional,linux,package setup() { - skipIfNotLinux + skipIfNotLinux + skipIfPackageNotInstalled if ! command -v rpm &> /dev/null; then skip "Skipping test: no RPM command" fi export PACKAGE_NAME="fluentdo-agent" - if ! rpm -qa | grep -q "$PACKAGE_NAME" ; then - skip "Skipping test: $PACKAGE_NAME RPM not installed" - fi } teardown() {