From 023559b98cbda47e02a73b7cdb10e743fe5b4e53 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 1 Mar 2019 16:01:48 +0000 Subject: [PATCH 1/2] Allow flags to be passed to e2e and unit tests This allows e.g. $ make -f docker.Makefile fmt test-e2e-non-experimental TESTFLAGS="-test.run TestRunGoodArgument|TestRunGood" As well as adding the var to `$(ENVVARS)` we also need to use that when invocking the e2e image, the existing `$(DOCKER_RUN)` is not used here because the bind mounts differ. The other variables included in `$(ENVVARS)` are harmless when running the e2e tests. The `${TESTFLAGS}` envvar is already understood by `scripts/test/e2e/run`. Note that since this modifies `$(ENVVARS)` this is now also available to the unit test target too, so add the use to the invocation so it takes effect. Signed-off-by: Ian Campbell --- Makefile | 2 +- docker.Makefile | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 10f07793fb..64e01609ff 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ clean: ## remove build artifacts .PHONY: test-unit test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit - gotestsum -- $(shell go list ./... | grep -vE '/vendor/|/e2e/') + gotestsum $(TESTFLAGS) -- $(shell go list ./... | grep -vE '/vendor/|/e2e/') .PHONY: test test: test-unit ## run tests diff --git a/docker.Makefile b/docker.Makefile index 06502b9b31..ce770ca9c6 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -21,7 +21,7 @@ ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y) DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build" endif VERSION = $(shell cat VERSION) -ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM +ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS # build docker image (dockerfiles/Dockerfile.build) .PHONY: build_docker_image @@ -141,15 +141,15 @@ test-e2e: test-e2e-non-experimental test-e2e-experimental test-e2e-connhelper-ss .PHONY: test-e2e-experimental test-e2e-experimental: build_e2e_image # run experimental e2e tests - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME) + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 $(E2E_IMAGE_NAME) .PHONY: test-e2e-non-experimental test-e2e-non-experimental: build_e2e_image # run non-experimental e2e tests - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME) + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) $(E2E_IMAGE_NAME) .PHONY: test-e2e-connhelper-ssh test-e2e-connhelper-ssh: build_e2e_image # run experimental SSH-connection helper e2e tests - docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) + docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(ENVVARS) -e DOCKERD_EXPERIMENTAL=1 -e TEST_CONNHELPER=ssh $(E2E_IMAGE_NAME) .PHONY: help help: ## print this help From e1a7b563089d51a292b45c87c7f9437bd33e14b0 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 11 Mar 2019 16:02:55 +0000 Subject: [PATCH 2/2] Allow control over dirs passed to e2e and unit tests Allows e.g.: $ make -f docker.Makefile TESTDIRS=./cli/command/trust/... test-unit Signed-off-by: Ian Campbell --- Makefile | 2 +- docker.Makefile | 2 +- scripts/test/e2e/run | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 64e01609ff..6f9abf9179 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ clean: ## remove build artifacts .PHONY: test-unit test-unit: ## run unit tests, to change the output format use: GOTESTSUM_FORMAT=(dots|short|standard-quiet|short-verbose|standard-verbose) make test-unit - gotestsum $(TESTFLAGS) -- $(shell go list ./... | grep -vE '/vendor/|/e2e/') + gotestsum $(TESTFLAGS) -- $${TESTDIRS:-$(shell go list ./... | grep -vE '/vendor/|/e2e/')} .PHONY: test test: test-unit ## run tests diff --git a/docker.Makefile b/docker.Makefile index ce770ca9c6..5571b498ef 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -21,7 +21,7 @@ ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y) DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build" endif VERSION = $(shell cat VERSION) -ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS +ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS # build docker image (dockerfiles/Dockerfile.build) .PHONY: build_docker_image diff --git a/scripts/test/e2e/run b/scripts/test/e2e/run index 51dc24ff17..70fb798a8f 100755 --- a/scripts/test/e2e/run +++ b/scripts/test/e2e/run @@ -70,7 +70,7 @@ function runtests { GOPATH="$GOPATH" \ PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \ DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \ - "$(command -v gotestsum)" -- ./e2e/... ${TESTFLAGS-} + "$(command -v gotestsum)" -- ${TESTDIRS:-./e2e/...} ${TESTFLAGS-} } export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"