Skip to content

Commit

Permalink
chore: allow to run tests only for specified packages
Browse files Browse the repository at this point in the history
This allows to do `make test TESTPKGS=./internal/app/machined`.

Also update Dockerfile slug as
moby/buildkit#1081 was merged into master.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira committed Jul 23, 2019
1 parent 45def0a commit 8c59adb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax = smira/dockerfile:master-experimental
# syntax = docker/dockerfile-upstream:master-experimental

ARG TOOLS
FROM $TOOLS AS tools
Expand Down Expand Up @@ -258,7 +258,8 @@ FROM base AS test-runner
RUN unlink /etc/ssl
COPY --from=rootfs-base / /
COPY hack/golang/test.sh /bin
RUN --security=insecure --mount=type=cache,target=/tmp --mount=type=cache,target=/root/.cache /bin/test.sh
ARG TESTPKGS
RUN --security=insecure --mount=type=cache,target=/tmp --mount=type=cache,target=/root/.cache /bin/test.sh ${TESTPKGS}
FROM scratch AS test
COPY --from=test-runner /src/coverage.txt /coverage.txt

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ DOCKER_ARGS ?=
# to allow tests to run containerd
DOCKER_TEST_ARGS = --security-opt seccomp:unconfined --privileged -v /var/lib/containerd/ -v /tmp/

TESTPKGS ?= ./...

all: ci drone

.PHONY: drone
Expand Down Expand Up @@ -209,6 +211,7 @@ test: buildkitd
build \
--opt target=$@ \
--output type=local,dest=./ \
--opt build-arg:TESTPKGS=$(TESTPKGS) \
$(COMMON_ARGS)

.PHONY: lint
Expand Down
15 changes: 7 additions & 8 deletions hack/golang/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

set -e

CGO_ENABLED=1

perform_tests() {
echo "Performing tests"
go test -v -covermode=atomic -coverprofile=coverage.txt ./...
echo "Performing tests on $1"
go test -v -covermode=atomic -coverprofile=coverage.txt "$1"
}

perform_short_tests() {
echo "Performing short tests"
go test -v -short ./...
echo "Performing short tests on $1"
go test -v -short "$1"
}

case $1 in
--short)
perform_short_tests
shift
perform_short_tests "${1:-./...}"
;;
*)
perform_tests
perform_tests "${1:-./...}"
;;
esac

Expand Down

0 comments on commit 8c59adb

Please sign in to comment.