From 1d3c3995edf7866b4f0ed8879a68f6b00aeaf5d8 Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Sun, 12 Jan 2020 16:04:29 -0800 Subject: [PATCH] End to End tests framework --- Makefile | 12 ++++++++++ examples/helloWorld/README.md | 32 +++++++++++++++++++++++-- hack/testExamplesE2EAgainstKustomize.sh | 13 ++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100755 hack/testExamplesE2EAgainstKustomize.sh diff --git a/Makefile b/Makefile index c9e5f4b54..77b8fe954 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ verify-kustomize: \ test-examples-kustomize-against-HEAD \ test-examples-kustomize-against-latest +.PHONY: verify-kustomize-e2e +verify-kustomize-e2e: test-examples-e2e-kustomize-against-HEAD + # Other builds in this repo might want a different linter version. # Without one Makefile to rule them all, the different makes # cannot assume that golanci-lint is at the version they want @@ -48,6 +51,11 @@ $(MYGOBIN)/goimports: cd api; \ go install golang.org/x/tools/cmd/goimports +# Install resource from whatever is checked out. +$(MYGOBIN)/resource: + cd cmd/resource; \ + go install . + # To pin pluginator, use this recipe instead: # cd api; # go install sigs.k8s.io/kustomize/pluginator/v2 @@ -193,6 +201,10 @@ test-unit-kustomize-all: \ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip ./hack/testExamplesAgainstKustomize.sh HEAD +.PHONY: +test-examples-e2e-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip $(MYGOBIN)/resource + ./hack/testExamplesE2EAgainstKustomize.sh HEAD + .PHONY: test-examples-kustomize-against-latest: $(MYGOBIN)/mdrip ( \ diff --git a/examples/helloWorld/README.md b/examples/helloWorld/README.md index fcd36bb4c..0ec226d5b 100644 --- a/examples/helloWorld/README.md +++ b/examples/helloWorld/README.md @@ -22,7 +22,7 @@ Steps: First define a place to work: - + ``` DEMO_HOME=$(mktemp -d) ``` @@ -44,7 +44,7 @@ To keep this document shorter, the base resources are off in a supplemental data directory rather than declared here as HERE documents. Download them: - + ``` BASE=$DEMO_HOME/base mkdir -p $BASE @@ -309,3 +309,31 @@ To deploy, pipe the above commands to kubectl apply: > kustomize build $OVERLAYS/production |\ > kubectl apply -f - > ``` + +[Alpha] To do end to end tests using kustomize, use the following commands on any folder. You should have GOPATH set up and "kind" installed(https://github.com/kubernetes-sigs/kind). + + +``` +MYGOBIN=$GOPATH/bin +kind delete cluster; +kind create cluster; +$MYGOBIN/kustomize build $BASE | kubectl apply -f -; +status=$(mktemp); +$MYGOBIN/resource status events $BASE #Waits for all transient events to finish +$MYGOBIN/resource status fetch $BASE > $status + +test 1 == \ + $(grep "apps/v1/Deployment" $status | grep "Deployment is available. Replicas: 3" | wc -l); \ + echo $? + +test 1 == \ + $(grep "v1/ConfigMap" $status | grep "Resource is always ready" | wc -l); \ + echo $? + +test 1 == \ + $(grep "v1/Service" $status | grep "Service is ready" | wc -l); \ + echo $? + +$MYGOBIN/kustomize build $BASE | kubectl delete -f -; +kind delete cluster; +``` \ No newline at end of file diff --git a/hack/testExamplesE2EAgainstKustomize.sh b/hack/testExamplesE2EAgainstKustomize.sh new file mode 100755 index 000000000..a6c44195b --- /dev/null +++ b/hack/testExamplesE2EAgainstKustomize.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# +# Copyright 2019 The Kubernetes Authors. +# SPDX-License-Identifier: Apache-2.0 + +set -o nounset +set -o errexit +set -o pipefail + +mdrip --blockTimeOut 60m0s --mode test \ + --label testE2EAgainstLatestRelease examples + +echo "Example e2e tests passed against ${version}."