Skip to content

Commit

Permalink
Standardize the way scripts are run
Browse files Browse the repository at this point in the history
* `scripts/run-tests.sh` can run all tests
* delete smoke/crd tests run scripts

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
  • Loading branch information
danail-branekov and georgethebeatle committed Aug 16, 2023
1 parent baba5ea commit 12d8d56
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ test-e2e: build-dorifi
./scripts/run-tests.sh tests/e2e

test-crds: build-dorifi
./tests/crds/run-tests.sh
./scripts/run-tests.sh tests/crds

test-smoke: build-dorifi
./tests/smoke/run-tests.sh
./scripts/run-tests.sh tests/smoke


build-dorifi:
Expand Down
114 changes: 80 additions & 34 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ENVTEST_ASSETS_DIR="${SCRIPT_DIR}/../testbin"
mkdir -p "${ENVTEST_ASSETS_DIR}"
extra_args=()

function getTestDir() {
for arg in "$@"; do
Expand All @@ -14,15 +17,45 @@ function getTestDir() {
echo "."
}

ENVTEST_ASSETS_DIR="${SCRIPT_DIR}/../testbin"
mkdir -p "${ENVTEST_ASSETS_DIR}"
function deploy_korifi() {
if [ -z "${SKIP_DEPLOY:-}" ]; then
"${SCRIPT_DIR}/deploy-on-kind.sh" e2e
fi

extra_args=()
if [[ -n "${GINKGO_NODES:-}" ]]; then
extra_args+=("--procs=${GINKGO_NODES}")
fi
echo "waiting for ClusterBuilder to be ready..."
kubectl wait --for=condition=ready clusterbuilder --all=true --timeout=15m
}

function configure_e2e_tests() {
export ROOT_NAMESPACE="${ROOT_NAMESPACE:-cf}"
export APP_FQDN="${APP_FQDN:-apps-127-0-0-1.nip.io}"
export API_SERVER_ROOT="${API_SERVER_ROOT:-https://localhost}"

deploy_korifi

extra_args+=("--poll-progress-after=3m30s")
}

function configure_crd_tests() {
export NO_PARALLEL=true
export CRDS_TEST_API_ENDPOINT="${CRDS_TEST_API_ENDPOINT:-https://localhost}"
export CRDS_TEST_SKIP_SSL="${CRDS_TEST_SKIP_SSL:-true}"

deploy_korifi
}

function configure_smoke_tests() {
export NO_PARALLEL=true
export SMOKE_TEST_USER="${SMOKE_TEST_USER:-cf-admin}"
export SMOKE_TEST_APPS_DOMAIN="${SMOKE_TEST_APPS_DOMAIN:-apps-127-0-0-1.nip.io}"
export SMOKE_TEST_APP_ROUTE_PROTOCOL="${SMOKE_TEST_APP_ROUTE_PROTOCOL:-https}"
export SMOKE_TEST_API_ENDPOINT="${SMOKE_TEST_API_ENDPOINT:-https://localhost}"
export SMOKE_TEST_SKIP_SSL="${SMOKE_TEST_SKIP_SSL:-true}"

if ! grep -q e2e <(echo "$@"); then
deploy_korifi
}

function configure_non_e2e_tests() {
grepFlags="-sq"

if [[ -z "${NON_RECURSIVE_TEST:-}" ]]; then
Expand All @@ -35,40 +68,53 @@ if ! grep -q e2e <(echo "$@"); then
fi

extra_args+=("--poll-progress-after=60s" "--skip-package=e2e")
else
export ROOT_NAMESPACE="${ROOT_NAMESPACE:-cf}"
export APP_FQDN="${APP_FQDN:-apps-127-0-0-1.nip.io}"
export KUBECONFIG="${KUBECONFIG:-${HOME}/kube/e2e.yml}"
export API_SERVER_ROOT="${API_SERVER_ROOT:-https://localhost}"
}

if [ -z "${SKIP_DEPLOY:-}" ]; then
"${SCRIPT_DIR}/deploy-on-kind.sh" e2e
function run_ginkgo() {
if [[ -n "${GINKGO_NODES:-}" ]]; then
extra_args+=("--procs=${GINKGO_NODES}")
fi

extra_args+=("--poll-progress-after=3m30s")
if [[ -z "${NO_COVERAGE:-}" ]]; then
extra_args+=("--coverprofile=cover.out" "--coverpkg=code.cloudfoundry.org/korifi/...")
fi

echo "waiting for ClusterBuilder to be ready..."
kubectl wait --for=condition=ready clusterbuilder --all=true --timeout=15m
fi
if [[ -z "${NON_RECURSIVE_TEST:-}" ]]; then
extra_args+=("-r")
fi

if [[ -n "${UNTIL_IT_FAILS:-}" ]]; then
extra_args+=("--until-it-fails")
fi

if [[ -n "${SEED:-}" ]]; then
extra_args+=("--seed=${SEED}")
fi

if [[ -z "${NO_COVERAGE:-}" ]]; then
extra_args+=("--coverprofile=cover.out" "--coverpkg=code.cloudfoundry.org/korifi/...")
fi
if [[ -z "${NO_RACE:-}" ]]; then
extra_args+=("--race")
fi

if [[ -z "${NO_PARALLEL:-}" ]]; then
extra_args+=("-p")
fi

if [[ -z "${NON_RECURSIVE_TEST:-}" ]]; then
extra_args+=("-r")
fi
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites "${extra_args[@]}" $@
}

if [[ -n "${UNTIL_IT_FAILS:-}" ]]; then
extra_args+=("--until-it-fails")
fi
function main() {

if [[ -n "${SEED:-}" ]]; then
extra_args+=("--seed=${SEED}")
fi
if grep -q "tests/e2e" <(echo "$@"); then
configure_e2e_tests $@
elif grep -q "tests/crds" <(echo "$@"); then
configure_crd_tests $@
elif grep -q "tests/smoke" <(echo "$@"); then
configure_smoke_tests $@
else
configure_non_e2e_tests $@
fi

if [[ -z "${NO_RACE:-}" ]]; then
extra_args+=("--race")
fi
run_ginkgo $@
}

go run github.com/onsi/ginkgo/v2/ginkgo -p --randomize-all --randomize-suites "${extra_args[@]}" $@
main $@
22 changes: 0 additions & 22 deletions tests/crds/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions tests/crds/run-tests.sh

This file was deleted.

17 changes: 0 additions & 17 deletions tests/smoke/run-tests.sh

This file was deleted.

0 comments on commit 12d8d56

Please sign in to comment.