From 75ab151eed2d6aff59eb89dd63509ab54b7f8fdd Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Thu, 7 Feb 2019 12:26:19 +0000 Subject: [PATCH] Containerize integration test --- .gitignore | 3 ++- Dockerfile | 4 +++- Makefile | 59 +++++++++++++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index c01a5f4f49..2bf11af307 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ # Release config file backups .goreleaser.brew.combined.yml -# Locally built binary +# Locally built binaries /eksctl +/eksctl-integration-test # Bad deps vendor/k8s.io/kops/docs diff --git a/Dockerfile b/Dockerfile index 46e0b162aa..a994ec0fb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,10 +35,12 @@ ENV JUNIT_REPORT_DIR $GOPATH/src/github.com/weaveworks/eksctl/test-results/ginkg RUN mkdir -p "${JUNIT_REPORT_DIR}" WORKDIR $EKSCTL -RUN make $TEST_TARGET RUN make lint +RUN make $TEST_TARGET RUN make build \ && cp ./eksctl /out/usr/local/bin/eksctl +RUN make build-integration-test \ + && cp ./eksctl-integration-test /out/usr/local/bin/eksctl-integration-test RUN go build ./vendor/github.com/kubernetes-sigs/aws-iam-authenticator/cmd/aws-iam-authenticator \ && cp ./aws-iam-authenticator /out/usr/local/bin/aws-iam-authenticator diff --git a/Makefile b/Makefile index 4ccf069e6a..4b7d635285 100644 --- a/Makefile +++ b/Makefile @@ -8,14 +8,6 @@ EKSCTL_IMAGE ?= weaveworks/eksctl:latest .DEFAULT_GOAL := help -ifneq ($(TEST_V),) -TEST_ARGS ?= -v -ginkgo.v -endif - -ifneq ($(DELETE_TEST_CLUSTER),) -INTEGRATION_TEST_ARGS ?= -eksctl.delete=false -endif - ##@ Dependencies .PHONY: install-build-deps @@ -30,34 +22,59 @@ build: ## Build eksctl ##@ Testing & CI +ifneq ($(TEST_V),) +UNIT_TEST_ARGS ?= -v -ginkgo.v +INTEGRATION_TEST_ARGS ?= -test.v -ginkgo.v +endif + +.PHONY: ci +ci: lint test ## Target for CI system to invoke to run tests and linting + +LINTER ?= gometalinter ./... +.PHONY: lint +lint: ## Run linter over the codebase + @$(GOPATH)/bin/$(LINTER) + .PHONY: test test: generate ## Run unit test (and re-generate code under test) @git diff --exit-code pkg/nodebootstrap/assets.go > /dev/null || (git --no-pager diff pkg/nodebootstrap/assets.go; exit 1) @git diff --exit-code ./pkg/eks/mocks > /dev/null || (git --no-pager diff ./pkg/eks/mocks; exit 1) @$(MAKE) unit-test @test -z $(COVERALLS_TOKEN) || $(GOPATH)/bin/goveralls -coverprofile=coverage.out -service=circle-ci - @go test -tags integration ./integration/... -c && rm -f integration.test + @$(MAKE) build-integration-test .PHONY: unit-test unit-test: ## Run unit test only - @CGO_ENABLED=0 go test -covermode=count -coverprofile=coverage.out ./pkg/... ./cmd/... $(TEST_ARGS) + @CGO_ENABLED=0 go test -covermode=count -coverprofile=coverage.out ./pkg/... ./cmd/... $(UNIT_TEST_ARGS) -LINTER ?= gometalinter ./... -.PHONY: lint -lint: ## Run linter over the codebase - @$(GOPATH)/bin/$(LINTER) +.PHONY: build-integration-test +build-integration-test: ## Build integration test binary + @go test -tags integration ./integration/... -c -o ./eksctl-integration-test -.PHONY: ci -ci: test lint ## Target for CI system to invoke to run tests and linting +.PHONY: integration-test +integration-test: build build-integration-test ## Run the integration tests (with cluster creation and cleanup) + @./eksctl-integration-test -test.timeout 60m \ + $(INTEGRATION_TEST_ARGS) + +.PHONY: integration-test-container +integration-test-container: eksctl-image + @docker run \ + --env=AWS_PROFILE \ + --volume=$(HOME)/.aws:/root/.aws \ + $(EKSCTL_IMAGE) \ + eksctl-integration-test \ + -eksctl.path=/usr/local/bin/eksctl \ + -eksctl.kubeconfig=/tmp/kubeconfig \ + $(INTEGRATION_TEST_ARGS) TEST_CLUSTER ?= integration-test-dev .PHONY: integration-test-dev -integration-test-dev: build ## Run the integration tests without cluster teardown. For use when developing integration tests. +integration-test-dev: build build-integration-test ## Run the integration tests without cluster teardown. For use when developing integration tests. @./eksctl utils write-kubeconfig \ --auto-kubeconfig \ --name=$(TEST_CLUSTER) - @go test -tags integration -timeout 21m ./integration/... \ - $(TEST_ARGS) \ + @./eksctl-integration-test -test.timeout 21m \ + $(INTEGRATION_TEST_ARGS) \ -args \ -eksctl.cluster=$(TEST_CLUSTER) \ -eksctl.create=false \ @@ -70,10 +87,6 @@ create-integration-test-dev-cluster: build ## Create a test cluster for use when delete-integration-test-dev-cluster: build ## Delete the test cluster for use when developing integration tests @./eksctl delete cluster --name=integration-test-dev --auto-kubeconfig -.PHONY: integration-test -integration-test: build ## Run the integration tests (with cluster creation and cleanup) - @go test -tags integration -timeout 60m ./integration/... $(TEST_ARGS) $(INTEGRATION_TEST_ARGS) - ##@ Code Generation .PHONY: generate