| #!/usr/bin/env bash |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| set -Eeuo pipefail |
| |
| COVERAGE=0 |
| ARGS=() |
| for arg in "$@"; do |
| case "$arg" in |
| --coverage) COVERAGE=1 ;; |
| *) ARGS+=("$arg") ;; |
| esac |
| done |
| |
| SDK="${ARGS[0]:-all}" |
| FEATURE="${ARGS[1]:-all}" |
| |
| log(){ printf "%b\n" "$*"; } |
| |
| usage(){ |
| log "Usage: $0 [--coverage] <sdk> [feature]" |
| log "" |
| log " sdk: rust | python | php | go | go-race | node | csharp | java | cpp | all | clean (default: all)" |
| log " feature: basic_messaging | leader_redirection | all (default: all)" |
| log "" |
| log "Examples:" |
| log " $0 rust # run all features for Rust" |
| log " $0 rust basic_messaging # run only basic_messaging for Rust" |
| log " $0 all leader_redirection # run leader_redirection for all supporting SDKs" |
| log " $0 --coverage go basic_messaging" |
| } |
| |
| case "$FEATURE" in |
| basic_messaging|leader_redirection|all) ;; |
| *) |
| log "Unknown feature: ${FEATURE}" |
| usage |
| exit 2 ;; |
| esac |
| |
| export DOCKER_BUILDKIT=1 BDD_FEATURE="$FEATURE" GO_TEST_EXTRA_FLAGS="${GO_TEST_EXTRA_FLAGS:-}" |
| |
| cd "$(dirname "$0")/../bdd" |
| |
| ALL_COMPOSE_FILES=( |
| -f docker-compose.yml |
| -f docker-compose.server.yml |
| -f docker-compose.cluster.yml |
| -f docker-compose.coverage.yml |
| ) |
| |
| COMPOSE_FILES=(-f docker-compose.yml) |
| case "$FEATURE" in |
| basic_messaging|leader_redirection|all) |
| COMPOSE_FILES+=(-f docker-compose.server.yml) ;; |
| esac |
| case "$FEATURE" in |
| leader_redirection|all) |
| COMPOSE_FILES+=(-f docker-compose.cluster.yml) ;; |
| esac |
| if [ "$COVERAGE" = "1" ]; then |
| COMPOSE_FILES+=(-f docker-compose.coverage.yml) |
| mkdir -p ../reports |
| fi |
| |
| cleanup(){ |
| log "π§Ή cleaning up containers & volumesβ¦" |
| docker compose "${ALL_COMPOSE_FILES[@]}" down -v --remove-orphans >/dev/null 2>&1 || true |
| } |
| trap cleanup EXIT INT TERM |
| |
| log "π§ͺ Running BDD tests for SDK: ${SDK}" |
| log "π Feature file: ${FEATURE}" |
| if [ "$COVERAGE" = "1" ]; then |
| log "π Coverage collection enabled β reports will be in ./reports/" |
| fi |
| |
| run_suite(){ |
| local svc="$1" emoji="$2" label="$3" |
| if [ "$FEATURE" = "leader_redirection" ]; then |
| case "$svc" in |
| rust-bdd|go-bdd|csharp-bdd) ;; |
| *) |
| if [ "$SDK" = "all" ]; then |
| log "β οΈ skipping ${svc%-bdd} (does not support ${FEATURE})" |
| return 0 |
| else |
| log "β ${SDK} does not support feature '${FEATURE}'" |
| return 1 |
| fi |
| ;; |
| esac |
| fi |
| |
| log "${emoji} ${label}..." |
| local code=0 |
| docker compose "${COMPOSE_FILES[@]}" \ |
| up --build --exit-code-from "$svc" "$svc" \ |
| || code=$? |
| docker compose "${COMPOSE_FILES[@]}" \ |
| down -v --remove-orphans >/dev/null 2>&1 || true |
| return "$code" |
| } |
| |
| case "$SDK" in |
| rust) run_suite rust-bdd "π¦" "Running Rust BDD tests" ;; |
| python) run_suite python-bdd "π" "Running Python BDD tests" ;; |
| php) run_suite php-bdd "π" "Running PHP BDD tests" ;; |
| go) run_suite go-bdd "πΉ" "Running Go BDD tests" ;; |
| go-race) |
| if [ "$COVERAGE" = "1" ]; then |
| log "β οΈ coverage collection automatically drops -race flag as coverage does not need -race" |
| fi |
| export GO_TEST_EXTRA_FLAGS="-race" |
| run_suite go-bdd "πΉβ‘" "Running Go BDD tests with data race detector" |
| ;; |
| node) run_suite node-bdd "π’π" "Running Node BDD tests" ;; |
| csharp) run_suite csharp-bdd "π·" "Running C# BDD tests" ;; |
| java) run_suite java-bdd "β" "Running Java BDD tests" ;; |
| cpp) run_suite cpp-bdd "βοΈ" "Running C++ BDD tests" ;; |
| all) |
| run_suite rust-bdd "π¦" "Running Rust BDD tests" || exit $? |
| run_suite python-bdd "π" "Running Python BDD tests" || exit $? |
| run_suite php-bdd "π" "Running PHP BDD tests" || exit $? |
| run_suite go-bdd "πΉ" "Running Go BDD tests" || exit $? |
| GO_TEST_EXTRA_FLAGS="-race" \ |
| run_suite go-bdd "πΉβ‘" "Running Go BDD tests with data race detector" || exit $? |
| run_suite node-bdd "π’π" "Running Node BDD tests" || exit $? |
| run_suite csharp-bdd "π·" "Running C# BDD tests" || exit $? |
| run_suite java-bdd "β" "Running Java BDD tests" || exit $? |
| run_suite cpp-bdd "βοΈ" "Running C++ BDD tests" || exit $? |
| ;; |
| clean) |
| cleanup |
| exit 0 ;; |
| *) |
| log "β Unknown SDK: ${SDK}" |
| usage |
| exit 2 ;; |
| esac |
| |
| log "β
BDD tests completed for: sdk=${SDK} feature=${FEATURE}" |