From 17151b99eadd4402e7c38a4808d3f186b55df31e Mon Sep 17 00:00:00 2001 From: mattjmcnaughton Date: Mon, 4 Jun 2018 21:17:54 -0400 Subject: [PATCH] Add containerized options for tests in Makefile Add an option to run the `test-unit`, `test-style`, and `test` steps from the `Makefile` insides of a docker container. Doing so isolates this component of helm development from any other aspect of your global go environment. These commands all have the name `docker-*`. Long term, there may be reproducibility benefits to running all of the Make steps in a container by default, in which case `containerized-test-unit` could become `test-unit`. --- Makefile | 23 +++++++++++++++++++++++ docs/developers.md | 6 +++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6264cd814..9b8588712 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ DOCKER_REGISTRY ?= gcr.io IMAGE_PREFIX ?= kubernetes-helm +DEV_IMAGE ?= golang:1.10 SHORT_NAME ?= tiller SHORT_NAME_RUDDER ?= rudder TARGETS ?= darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x windows/amd64 @@ -87,17 +88,39 @@ test: TESTFLAGS += -race -v test: test-style test: test-unit +.PHONY: docker-test +docker-test: docker-binary +docker-test: TESTFLAGS += -race -v +docker-test: docker-test-style +docker-test: docker-test-unit + .PHONY: test-unit test-unit: @echo @echo "==> Running unit tests <==" HELM_HOME=/no/such/dir $(GO) test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS) +.PHONY: docker-test-unit +docker-test-unit: check-docker + docker run \ + -v $(shell pwd):/go/src/k8s.io/helm \ + -w /go/src/k8s.io/helm \ + $(DEV_IMAGE) \ + bash -c "HELM_HOME=/no/such/dir go test $(GOFLAGS) -run $(TESTS) $(PKG) $(TESTFLAGS)" + .PHONY: test-style test-style: @scripts/validate-go.sh @scripts/validate-license.sh +.PHONY: docker-test-style +docker-test-style: check-docker + docker run \ + -v $(CURDIR):/go/src/k8s.io/helm \ + -w /go/src/k8s.io/helm \ + $(DEV_IMAGE) \ + bash -c "scripts/validate-go.sh && scripts/validate-license.sh" + .PHONY: protoc protoc: $(MAKE) -C _proto/ all diff --git a/docs/developers.md b/docs/developers.md index e18c28d5d..ca6b591fe 100644 --- a/docs/developers.md +++ b/docs/developers.md @@ -27,7 +27,8 @@ This will build both Helm and Tiller. `make bootstrap` will attempt to install certain tools if they are missing. To run all the tests (without running the tests for `vendor/`), run -`make test`. +`make test`. To run all tests in a containerized environment, run `make +docker-test`. To run Helm and Tiller locally, you can run `bin/helm` or `bin/tiller`. @@ -209,6 +210,9 @@ We follow the Go coding style standards very closely. Typically, running We also typically follow the conventions recommended by `go lint` and `gometalinter`. Run `make test-style` to test the style conformance. +If you do not want to install all the linters from `gometalinter` into your +global Go environment, you can run `make docker-test-style` which will +run the same tests, but isolated within a docker container. Read more: