Skip to content

Commit

Permalink
Run the end-to-end tests in presubmit (knative#106)
Browse files Browse the repository at this point in the history
The end-to-end tests are run only if the build and unit tests pass.

Bonus:
* assorted minor cleanups in the script
* partially addresses issue knative/serving#503
* updates to e2e-tests.sh:
  - reset to the default namespace after creating the cluster
  - create test cluster in us-central-1a, as us-east-1d is reaching its resource limit
  - dump info about the project used, for test diagnostic purposes
  • Loading branch information
adrcunha authored Apr 5, 2018
1 parent 7f904ae commit 116ba7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion tests/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# Test cluster parameters and location of generated test images
readonly E2E_CLUSTER_NAME=ela-e2e-cluster
readonly E2E_CLUSTER_ZONE=us-east1-d
readonly E2E_CLUSTER_ZONE=us-central1-a
readonly E2E_CLUSTER_NODES=2
readonly E2E_CLUSTER_MACHINE=n1-standard-2
readonly GKE_VERSION=v1.9.4-gke.1
Expand Down Expand Up @@ -160,6 +160,8 @@ if [[ -z ${K8S_CLUSTER_OVERRIDE} ]]; then
kubectl --username=admin --password=$passwd create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user=${K8S_USER_OVERRIDE}
# Make sure we're in the default namespace
kubectl config set-context $K8S_CLUSTER_OVERRIDE --namespace=default
fi
readonly USING_EXISTING_CLUSTER

Expand All @@ -172,6 +174,8 @@ fi
echo "================================================="
echo "* Cluster is ${K8S_CLUSTER_OVERRIDE}"
echo "* Docker is ${DOCKER_REPO_OVERRIDE}"
echo "*** Project info ***"
gcloud compute project-info describe

header "Building and starting the controller"
trap teardown EXIT
Expand Down
25 changes: 18 additions & 7 deletions tests/presubmit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
set -o errexit
set -o pipefail

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
OG_DOCKER_REPO="${DOCKER_REPO_OVERRIDE}"
# Useful environment variables
readonly BUILDCRD_ROOT=$(dirname ${BASH_SOURCE})/..
[[ $USER == "prow" ]] && IS_PROW=1 || IS_PROW=0
readonly IS_PROW

set -o nounset
# Save *_OVERRIDE variables in case a cleanup is required.
readonly OG_DOCKER_REPO="${DOCKER_REPO_OVERRIDE}"

function restore_env() {
export DOCKER_REPO_OVERRIDE="${OG_DOCKER_REPO}"
}

function cleanup() {
header "Cleanup (teardown)"
export DOCKER_REPO_OVERRIDE="${OG_DOCKER_REPO}"
restore_env
# --expunge is a workaround for https://github.com/elafros/elafros/issues/366
bazel clean --expunge || true
}
Expand All @@ -39,13 +46,13 @@ function header() {
echo "================================================="
}

cd ${SCRIPT_ROOT}
cd ${BUILDCRD_ROOT}

# Set the required env vars to dummy values to satisfy bazel.
export DOCKER_REPO_OVERRIDE=REPO_NOT_SET

# For local runs, cleanup before and after the tests.
if [[ ! $USER == "prow" ]]; then
if (( ! IS_PROW )); then
trap cleanup EXIT
header "Cleanup (setup)"
# --expunge is a workaround for https://github.com/elafros/elafros/issues/366
Expand All @@ -58,7 +65,11 @@ fi
header "Building phase"
bazel build //cmd/... //pkg/...

# Step 2: Run tests.
# Step 2: Run unit tests.
header "Testing phase"
bazel test //cmd/... //pkg/...

# Step 3: Run end-to-end tests.
# Restore environment variables, let e2e-tests.sh handle them.
restore_env
./tests/e2e-tests.sh

0 comments on commit 116ba7b

Please sign in to comment.