From 79e29601986b5c08e2426098a68e79a900eec72a Mon Sep 17 00:00:00 2001 From: "Maciej \"Iwan\" Iwanowski" Date: Thu, 23 Apr 2020 10:52:19 +0200 Subject: [PATCH] Ability to run unit tests in podman Signed-off-by: Maciej "Iwan" Iwanowski --- Makefile | 8 +++++--- build/{unit-in-docker.sh => unit-in-container.sh} | 11 ++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) rename build/{unit-in-docker.sh => unit-in-container.sh} (82%) diff --git a/Makefile b/Makefile index a49b60a4..1c85d6a3 100644 --- a/Makefile +++ b/Makefile @@ -32,10 +32,12 @@ test: @$(GO) test -short -race $(pkgs) @cd cmd && $(GO) test -short -race $(cmd_pkgs) -docker-test: - @echo ">> runinng tests in docker" - @./build/unit-in-docker.sh +container-test: + @echo ">> runinng tests in a container" + @./build/unit-in-container.sh +docker-test: container-test + @echo "docker-test target is deprecated, use container-test instead" test-integration: GO_FLAGS="-race" ./build/build.sh diff --git a/build/unit-in-docker.sh b/build/unit-in-container.sh similarity index 82% rename from build/unit-in-docker.sh rename to build/unit-in-container.sh index c85c5fd8..a55f3d22 100755 --- a/build/unit-in-docker.sh +++ b/build/unit-in-container.sh @@ -16,6 +16,15 @@ set -e +CONTAINER_ENGINE=$(command -v docker || true) +if [ "$CONTAINER_ENGINE" == "" ]; then + CONTAINER_ENGINE=$(command -v podman || true) +fi +if [ "$CONTAINER_ENGINE" == "" ]; then + echo "Unable to find docker and podman. Exiting." + exit 1 +fi + function run_tests() { BUILD_CMD="go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ') && \ cd cmd && go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ')" @@ -24,7 +33,7 @@ function run_tests() { $BUILD_CMD" fi - docker run --rm \ + $CONTAINER_ENGINE run --rm \ -w /go/src/github.com/google/cadvisor \ -v ${PWD}:/go/src/github.com/google/cadvisor \ golang:${GOLANG_VERSION} \