Merge pull request #2510 from iwankgb/enabling_unit_tests_in_podman

Ability to run unit tests in podman
This commit is contained in:
David Ashpole 2020-04-23 08:43:01 -07:00 committed by GitHub
commit 74c40b7b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -32,10 +32,12 @@ test:
@$(GO) test -short -race $(pkgs) @$(GO) test -short -race $(pkgs)
@cd cmd && $(GO) test -short -race $(cmd_pkgs) @cd cmd && $(GO) test -short -race $(cmd_pkgs)
docker-test: container-test:
@echo ">> runinng tests in docker" @echo ">> runinng tests in a container"
@./build/unit-in-docker.sh @./build/unit-in-container.sh
docker-test: container-test
@echo "docker-test target is deprecated, use container-test instead"
test-integration: test-integration:
GO_FLAGS="-race" ./build/build.sh GO_FLAGS="-race" ./build/build.sh

View File

@ -16,6 +16,15 @@
set -e 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() { function run_tests() {
BUILD_CMD="go test $GO_FLAGS $(go list $GO_FLAGS ./... | grep -v 'vendor\|integration' | tr '\n' ' ') && \ 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' ' ')" 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" $BUILD_CMD"
fi fi
docker run --rm \ $CONTAINER_ENGINE run --rm \
-w /go/src/github.com/google/cadvisor \ -w /go/src/github.com/google/cadvisor \
-v ${PWD}:/go/src/github.com/google/cadvisor \ -v ${PWD}:/go/src/github.com/google/cadvisor \
golang:${GOLANG_VERSION} \ golang:${GOLANG_VERSION} \