toolbox/toolbox-Test-fixes-for-gati...

221 lines
6.1 KiB
Diff

From b3eda81c7143221c78fd23d8a645e28f033b3963 Mon Sep 17 00:00:00 2001
From: Oliver Gutierrez <ogutsua@gmail.com>
Date: Tue, 14 Sep 2021 13:41:17 +0100
Subject: [PATCH] Tests fixes for gating
diff --git a/test/system/002-help.bats b/test/system/002-help.bats
index 4ff02c6..cca3da4 100644
--- a/test/system/002-help.bats
+++ b/test/system/002-help.bats
@@ -4,6 +4,10 @@ load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'libs/helpers.bash'
+setup() {
+ check_xdg_runtime_dir
+}
+
@test "help: Run command 'help'" {
run $TOOLBOX help
diff --git a/test/system/101-create.bats b/test/system/101-create.bats
index 3cc3eaf..63d4fcb 100644
--- a/test/system/101-create.bats
+++ b/test/system/101-create.bats
@@ -5,6 +5,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
+ check_xdg_runtime_dir
cleanup_containers
}
@@ -62,7 +63,7 @@ teardown() {
assert_success
assert_output --partial "Created container: fedora-toolbox-32"
- assert_output --partial "Enter with: toolbox enter fedora-toolbox-32"
+ assert_output --partial "Enter with: toolbox enter --release 32"
# Make sure the container has actually been created
run podman ps -a
diff --git a/test/system/102-list.bats b/test/system/102-list.bats
index 184ad6c..2f80843 100644
--- a/test/system/102-list.bats
+++ b/test/system/102-list.bats
@@ -5,6 +5,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
+ check_xdg_runtime_dir
cleanup_all
}
@@ -61,14 +62,14 @@ teardown() {
run $TOOLBOX list --images
assert_success
- assert_output --partial "$(get_system_id)-toolbox:$(get_system_version)"
+ assert_output --partial "$(get_default_image_name)"
assert_output --partial "fedora-toolbox:32"
# Check containers
run $TOOLBOX list --containers
assert_success
- assert_output --partial "$(get_system_id)-toolbox-$(get_system_version)"
+ assert_output --partial "$(get_default_container_name)"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
@@ -76,9 +77,9 @@ teardown() {
run $TOOLBOX list
assert_success
- assert_output --partial "$(get_system_id)-toolbox:$(get_system_version)"
+ assert_output --partial "$(get_default_image_name)"
assert_output --partial "fedora-toolbox:32"
- assert_output --partial "$(get_system_id)-toolbox-$(get_system_version)"
+ assert_output --partial "$(get_default_container_name)"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
}
diff --git a/test/system/103-container.bats b/test/system/103-container.bats
index 01b61e5..554a329 100644
--- a/test/system/103-container.bats
+++ b/test/system/103-container.bats
@@ -14,7 +14,7 @@ teardown() {
@test "container: Check container starts without issues" {
- readonly CONTAINER_NAME="$(get_system_id)-toolbox-$(get_system_version)"
+ readonly CONTAINER_NAME="$(get_default_container_name)"
create_default_container
diff --git a/test/system/104-run.bats b/test/system/104-run.bats
index 026126b..03cf291 100644
--- a/test/system/104-run.bats
+++ b/test/system/104-run.bats
@@ -5,6 +5,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
+ check_xdg_runtime_dir
cleanup_containers
}
diff --git a/test/system/105-rm.bats b/test/system/105-rm.bats
index 9f1435b..68e3c03 100644
--- a/test/system/105-rm.bats
+++ b/test/system/105-rm.bats
@@ -5,6 +5,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
+ check_xdg_runtime_dir
cleanup_containers
}
diff --git a/test/system/106-rmi.bats b/test/system/106-rmi.bats
index 0ef0ebe..b48f802 100644
--- a/test/system/106-rmi.bats
+++ b/test/system/106-rmi.bats
@@ -5,6 +5,7 @@ load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
+ check_xdg_runtime_dir
cleanup_all
}
diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash
index d59d661..d44b69e 100644
--- a/test/system/libs/helpers.bash
+++ b/test/system/libs/helpers.bash
@@ -8,11 +8,10 @@ readonly TOOLBOX=${TOOLBOX:-toolbox}
readonly SKOPEO=$(command -v skopeo)
# Helpful globals
-readonly PROJECT_DIR=${PWD}
-readonly IMAGE_CACHE_DIR="${PROJECT_DIR}/image-cache"
+readonly IMAGE_CACHE_DIR="${BATS_RUN_TMPDIR}/image-cache"
# Images
-declare -Ag IMAGES=([busybox]="docker.io/library/busybox" \
+declare -Ag IMAGES=([busybox]="quay.io/toolbox_tests/busybox" \
[fedora]="registry.fedoraproject.org/fedora-toolbox" \
[rhel]="registry.access.redhat.com/ubi8")
@@ -245,6 +244,7 @@ function find_os_release() {
# Returns the content of field ID in os-release
function get_system_id() {
+ if [[ -z ${TOOLBOX_TEST_SYSTEM_ID} ]]; then
local os_release
os_release="$(find_os_release)"
@@ -255,19 +255,51 @@ function get_system_id() {
fi
echo $(awk -F= '/ID/ {print $2}' $os_release | head -n 1)
+ else
+ echo ${TOOLBOX_TEST_SYSTEM_ID}
+ fi
}
# Returns the content of field VERSION_ID in os-release
function get_system_version() {
- local os_release
+ if [[ -z ${TOOLBOX_TEST_VERSION_ID} ]]; then
+ local os_release
- os_release="$(find_os_release)"
+ os_release="$(find_os_release)"
- if [[ -z "$os_release" ]]; then
- echo ""
- return
+ if [[ -z "$os_release" ]]; then
+ echo ""
+ return
+ fi
+
+ echo $(awk -F= '/VERSION_ID/ {print $2}' $os_release | head -n 1)
+ else
+ echo ${TOOLBOX_TEST_VERSION_ID}
fi
+}
+
- echo $(awk -F= '/VERSION_ID/ {print $2}' $os_release | head -n 1)
+# Setup the XDG_RUNTIME_DIR variable if not set
+function check_xdg_runtime_dir() {
+ if [[ -z "${XDG_RUNTIME_DIR}" ]]; then
+ export XDG_RUNTIME_DIR="/run/user/${UID}"
+ fi
}
+
+
+function get_default_container_name() {
+ if [[ -z ${TOOLBOX_TEST_DEFAULT_CONTAINER_NAME} ]]; then
+ echo $(get_system_id)-toolbox-$(get_system_version)
+ else
+ echo ${TOOLBOX_TEST_DEFAULT_CONTAINER_NAME}
+ fi
+}
+
+function get_default_image_name() {
+ if [[ -z ${TOOLBOX_TEST_DEFAULT_IMAGE_NAME} ]]; then
+ echo $(get_system_id)-toolbox:$(get_system_version)
+ else
+ echo ${TOOLBOX_TEST_DEFAULT_IMAGE_NAME}
+ fi
+}
\ No newline at end of file
--
2.31.1