From f30bda80fa5ecaf377db2b1d3958b279333e8a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Mon, 3 Jun 2024 16:12:05 +0200 Subject: [PATCH] Rework how are unit test run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running unit tests from sources was failing with: ./tmt-test-wrapper.sh-default-0-default-0: line 1: cd: too many arguments Copy over the approach from osbuild repository. Signed-off-by: Tomáš Hozza --- plans/unit-tests.fmf | 1 + tests/unit-tests/main.fmf | 4 ++++ tests/unit-tests/run-unit-tests.sh | 24 ++++++++++++++++++++++++ tests/unit.fmf | 5 ----- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/unit-tests/main.fmf create mode 100755 tests/unit-tests/run-unit-tests.sh delete mode 100644 tests/unit.fmf diff --git a/plans/unit-tests.fmf b/plans/unit-tests.fmf index 7fc52d4..c0707fa 100644 --- a/plans/unit-tests.fmf +++ b/plans/unit-tests.fmf @@ -2,5 +2,6 @@ summary: Run unit tests from source discover: how: fmf dist-git-source: true + filter: tag:unit-test execute: how: tmt diff --git a/tests/unit-tests/main.fmf b/tests/unit-tests/main.fmf new file mode 100644 index 0000000..b4c96ec --- /dev/null +++ b/tests/unit-tests/main.fmf @@ -0,0 +1,4 @@ +summary: Run osbuild-composer unit tests from dist-git sources +tag: unit-test +duration: 1h +test: ./run-unit-tests.sh diff --git a/tests/unit-tests/run-unit-tests.sh b/tests/unit-tests/run-unit-tests.sh new file mode 100755 index 0000000..ea59569 --- /dev/null +++ b/tests/unit-tests/run-unit-tests.sh @@ -0,0 +1,24 @@ +#!/usr/bin/bash + +set -euxo pipefail + +source /etc/os-release + +# Move to the checked out git repo with the test plans +# this should be the root of the dist-git repo +cd "${TMT_TREE}" + +# install all test dependencies +sudo dnf install -y rpmdevtools +sudo dnf builddep -y osbuild-composer.spec + +# Move to the directory with sources +cd "${TMT_SOURCE_DIR}" + +# Extract the Source0 basename without extension +SRC_DIR=$(spectool --source 0 osbuild-composer.spec | sed 's/.\+\(osbuild-composer-[0-9]\+\)\.tar\.gz/\1/') + +# Move to the extracted sources directory (patches are applied by default) +cd "${SRC_DIR}" + +GOFLAGS="-mod=vendor -tags=exclude_graphdriver_btrfs" go test ./... diff --git a/tests/unit.fmf b/tests/unit.fmf deleted file mode 100644 index 16dfdee..0000000 --- a/tests/unit.fmf +++ /dev/null @@ -1,5 +0,0 @@ -summary: Run unit tests -require: - - golang -test: cd ../osbuild-composer-*/ && sudo dnf builddep -y osbuild-composer.spec && GOFLAGS="-mod=vendor -tags=exclude_graphdriver_btrfs" go test ./... -duration: 1h