From 5e4a9a30981b699b759cf88e0f2d4dc7e7995ebf Mon Sep 17 00:00:00 2001 From: Arthur Barr Date: Tue, 3 Oct 2017 16:05:08 +0100 Subject: [PATCH] Test image/chart variations --- Makefile | 42 +++++++++++++++++++++++-------- docs/developing.md | 34 +++++++++++++++++++++++++ test/kubernetes/helm_test_util.go | 24 +++++++++++++++--- 3 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 docs/developing.md diff --git a/Makefile b/Makefile index 19a7ba8..a977b81 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,15 @@ BUILD_SERVER_CONTAINER=build-server export GOARCH ?= amd64 # Don't set GOOS globally, so that tests can be run locally DOCKER_TAG_ARCH ?= x86_64 -DOCKER_IMAGE_DEVSERVER = mq-devserver:latest-$(DOCKER_TAG_ARCH) -DOCKER_IMAGE_ADVANCEDSERVER = mq-advancedserver:latest-$(DOCKER_TAG_ARCH) +DOCKER_TAG ?= latest-$(DOCKER_TAG_ARCH) +DOCKER_REPO_DEVSERVER ?= mq-devserver +DOCKER_REPO_ADVANCEDSERVER ?= mq-advancedserver +DOCKER_FULL_DEVSERVER = $(DOCKER_REPO_DEVSERVER):$(DOCKER_TAG) +DOCKER_FULL_ADVANCEDSERVER = $(DOCKER_REPO_ADVANCEDSERVER):$(DOCKER_TAG) +# Options to `go test` for the Docker tests +TEST_OPTS_DOCKER ?= +# Options to `go test` for the Kubernetes tests +TEST_OPTS_KUBERNETES ?= .PHONY: default default: build-devserver test @@ -76,13 +83,26 @@ build-cov: .PHONY: test-advancedserver test-advancedserver: build cd pkg/name && go test - cd test/docker && TEST_IMAGE=$(DOCKER_IMAGE_ADVANCEDSERVER) go test + cd test/docker && TEST_IMAGE=$(DOCKER_FULL_ADVANCEDSERVER) go test $(TEST_OPTS_DOCKER) .PHONY: test-devserver test-devserver: build - $(info $(SPACER)$(shell printf $(TITLE)"Test $(DOCKER_IMAGE_DEVSERVER)"$(END))) + $(info $(SPACER)$(shell printf $(TITLE)"Test $(DOCKER_FULL_DEVSERVER)"$(END))) cd pkg/name && go test - cd test/docker && TEST_IMAGE=$(DOCKER_IMAGE_DEVSERVER) go test + cd test/docker && TEST_IMAGE=$(DOCKER_FULL_DEVSERVER) go test + +.PHONY: test-kubernetes-devserver +test-kubernetes-devserver: build + $(call test-kubernetes,$(DOCKER_REPO_DEVSERVER),$(DOCKER_TAG),"../../charts/ibm-mqadvanced-server-dev") + +.PHONY: test-kubernetes-advancedserver +test-kubernetes-advancedserver: build + $(call test-kubernetes,$(DOCKER_REPO_ADVANCEDSERVER),$(DOCKER_TAG),"../../charts/ibm-mqadvanced-server-prod") + +define test-kubernetes + $(info $(SPACER)$(shell printf $(TITLE)"Test $1:$2 on Kubernetes"$(END))) + cd test/kubernetes && TEST_REPO=$1 TEST_TAG=$2 TEST_CHART=$3 go test $(TEST_OPTS_KUBERNETES) +endef define docker-build-mq # Create a temporary network to use for the build @@ -114,15 +134,15 @@ endef .PHONY: build-advancedserver build-advancedserver: build downloads/CNJR7ML.tar.gz - $(info $(SPACER)$(shell printf $(TITLE)"Build $(DOCKER_IMAGE_ADVANCEDSERVER)"$(END))) - $(call docker-build-mq,$(DOCKER_IMAGE_ADVANCEDSERVER),Dockerfile-server,CNJR7ML.tar.gz,"4486e8c4cc9146fd9b3ce1f14a2dfc5b","IBM MQ Advanced","9.0.3") - docker tag $(DOCKER_IMAGE_ADVANCEDSERVER) mq-advancedserver:9.0.3-$(DOCKER_TAG_ARCH) + $(info $(SPACER)$(shell printf $(TITLE)"Build $(DOCKER_FULL_ADVANCEDSERVER)"$(END))) + $(call docker-build-mq,$(DOCKER_FULL_ADVANCEDSERVER),Dockerfile-server,CNJR7ML.tar.gz,"4486e8c4cc9146fd9b3ce1f14a2dfc5b","IBM MQ Advanced","9.0.3") + docker tag $(DOCKER_FULL_ADVANCEDSERVER) $(DOCKER_REPO_ADVANCEDSERVER):9.0.3-$(DOCKER_TAG_ARCH) .PHONY: build-devserver build-devserver: build downloads/mqadv_dev903_ubuntu_x86-64.tar.gz - $(info $(shell printf $(TITLE)"Build $(DOCKER_IMAGE_DEVSERVER)"$(END))) - $(call docker-build-mq,$(DOCKER_IMAGE_DEVSERVER),Dockerfile-server,mqadv_dev903_ubuntu_x86-64.tar.gz,"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)","9.0.3") - docker tag $(DOCKER_IMAGE_DEVSERVER) mq-devserver:9.0.3-$(DOCKER_TAG_ARCH) + $(info $(shell printf $(TITLE)"Build $(DOCKER_FULL_DEVSERVER)"$(END))) + $(call docker-build-mq,$(DOCKER_FULL_DEVSERVER),Dockerfile-server,mqadv_dev903_ubuntu_x86-64.tar.gz,"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)","9.0.3") + docker tag $(DOCKER_FULL_DEVSERVER) $(DOCKER_REPO_DEVSERVER):9.0.3-$(DOCKER_TAG_ARCH) # .PHONY: build-server # build-server: build downloads/CNJR7ML.tar.gz diff --git a/docs/developing.md b/docs/developing.md new file mode 100644 index 0000000..22cae1e --- /dev/null +++ b/docs/developing.md @@ -0,0 +1,34 @@ +# Developing + +## Prerequisites +You need to ensure you have the following tools installed: + +* [Docker](https://www.docker.com/) +* [Go](https://golang.org/) +* [Glide](https://glide.sh/) +* [dep](https://github.com/golang/dep) (official Go dependency management tool) +* make + +For running the Kubernetes tests, a Kubernetes environment is needed, for example [Minikube](https://github.com/kubernetes/minikube) or [IBM Cloud Private](https://www.ibm.com/cloud-computing/products/ibm-cloud-private/). + +## Running the tests +There are three main sets of tests: + +1. Unit tests +2. Docker tests, which test a complete Docker image, using the Docker API +3. Kubernetes tests, which test the Helm charts (and the Docker image) via [Helm](https://helm.sh) + +### Running the tests +The unit and Docker tests can be run locally. For example: + +```bash +make test-devserver +``` + +### Running the Kubernetes tests + +For the Kubernetes tests, you need to have built the Docker image, and pushed it to the registry used by your Kubernetes cluster. Most of the configuration used by the tests is picked up from your `kubectl` configuration, but you will typically need to specify the image details. For example: + +```bash +DOCKER_REPO_DEVSERVER=mycluster.icp:8500/default/mq-devserver make test-kubernetes-devserver +``` diff --git a/test/kubernetes/helm_test_util.go b/test/kubernetes/helm_test_util.go index a123b7a..9e72dd7 100644 --- a/test/kubernetes/helm_test_util.go +++ b/test/kubernetes/helm_test_util.go @@ -33,11 +33,27 @@ import ( ) func imageName() string { - image, ok := os.LookupEnv("TEST_IMAGE") + v, ok := os.LookupEnv("TEST_REPO") if !ok { - image = "ibmcom/mq" + v = "ibmcom/mq" } - return image + return v +} + +func imageTag() string { + v, ok := os.LookupEnv("TEST_TAG") + if !ok { + v = "latest" + } + return v +} + +func chartName() string { + v, ok := os.LookupEnv("TEST_CHART") + if !ok { + v = "../../charts/ibm-mqadvanced-server-dev" + } + return v } // runCommand runs an OS command. On Linux it waits for the command to @@ -80,7 +96,7 @@ func inspectLogs(t *testing.T, cs *kubernetes.Clientset, release string) string } func helmInstall(t *testing.T, cs *kubernetes.Clientset, release string, values ...string) { - chart := "../../charts/ibm-mqadvanced-server-prod" + chart := chartName() tag := "latest" arg := []string{ "install",