From fcaf3d79f44f0aad34668e70ea1c967d949609e5 Mon Sep 17 00:00:00 2001 From: Alvaro Saurin Date: Mon, 20 Jan 2020 11:58:43 +0100 Subject: [PATCH] e2e tests for the registry Signed-off-by: Alvaro Saurin --- tests/02-registry.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 tests/02-registry.sh diff --git a/tests/02-registry.sh b/tests/02-registry.sh new file mode 100755 index 00000000..a18cd64d --- /dev/null +++ b/tests/02-registry.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +[ -d "$CURR_DIR" ] || { echo "FATAL: no current dir (maybe running in zsh?)"; exit 1; } + +# shellcheck source=./common.sh +source "$CURR_DIR/common.sh" + +######################################################################################### + +REGISTRY_NAME="registry.local" +REGISTRY_PORT="5000" +REGISTRY="$REGISTRY_NAME:$REGISTRY_PORT" +TEST_IMAGE="nginx:latest" + +check_registry() { + check_url $REGISTRY/v2/_catalog +} + +######################################################################################### + +info "Checking that $REGISTRY_NAME is resolvable" +grep -q $REGISTRY_NAME /etc/hosts +if [ $? -ne 0 ] ; then + [ "$CI" = "true" ] || abort "$REGISTRY_NAME is not in /etc/hosts: please add an entry manually." + + info "Adding '127.0.0.1 $REGISTRY_NAME' to /etc/hosts" + echo "127.0.0.1 $REGISTRY_NAME" | sudo tee -a /etc/hosts +else + passed "... good: $REGISTRY_NAME is in /etc/hosts" +fi + +info "Creating two clusters (with a registry)..." +$EXE create --wait 60 --name "c1" --api-port 6443 --enable-registry || failed "could not create cluster c1" +$EXE create --wait 60 --name "c2" --api-port 6444 --enable-registry || failed "could not create cluster c2" + +check_k3d_clusters "c1" "c2" || failed "error checking cluster" + +check_registry || abort "local registry not available at $REGISTRY" +passed "Local registry running at $REGISTRY" + +info "Deleting c1 cluster: the registry should remain..." +$EXE delete --name "c1" || failed "could not delete the cluster c1" +check_registry || abort "local registry not available at $REGISTRY after removing c1" +passed "The local registry is still running" + +info "Pulling a test image..." +docker pull $TEST_IMAGE +docker tag $TEST_IMAGE $REGISTRY/$TEST_IMAGE + +info "Pushing to $REGISTRY..." +docker push $REGISTRY/$TEST_IMAGE + +info "Using the image in the registry in the first cluster..." +cat <