| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| |
| |
| |
|
|
| |
| source "$(dirname "$0")/setup-go-workspace.sh" |
|
|
| echo "π§ͺ Running plugin tests..." |
|
|
| |
| cleanup_docker() { |
| echo "π§Ή Cleaning up Docker services..." |
| if command -v docker-compose >/dev/null 2>&1; then |
| docker-compose -f tests/docker-compose.yml down 2>/dev/null || true |
| elif docker compose version >/dev/null 2>&1; then |
| docker compose -f tests/docker-compose.yml down 2>/dev/null || true |
| fi |
| } |
|
|
| |
| trap cleanup_docker EXIT |
|
|
| |
| echo "π§ Starting dependencies of plugin tests..." |
| |
| if command -v docker-compose >/dev/null 2>&1; then |
| docker-compose -f tests/docker-compose.yml up -d |
| elif docker compose version >/dev/null 2>&1; then |
| docker compose -f tests/docker-compose.yml up -d |
| else |
| echo "β Neither docker-compose nor docker compose is available" |
| exit 1 |
| fi |
| sleep 20 |
|
|
| |
| if [ $# -gt 0 ] && [ -n "$1" ]; then |
| CHANGED_PLUGINS_JSON="$1" |
| |
| |
| if ! command -v jq >/dev/null 2>&1; then |
| echo "β Error: jq is required but not installed" |
| exit 1 |
| fi |
| |
| |
| if ! echo "$CHANGED_PLUGINS_JSON" | jq empty >/dev/null 2>&1; then |
| echo "β Error: Invalid JSON provided" |
| exit 1 |
| fi |
| |
| |
| if jq -e 'length==0' <<<"$CHANGED_PLUGINS_JSON" >/dev/null 2>&1; then |
| echo "βοΈ No plugins to test" |
| exit 0 |
| fi |
| |
| |
| if ! readarray -t PLUGINS < <(echo "$CHANGED_PLUGINS_JSON" | jq -r '.[]' 2>/dev/null); then |
| echo "β Error: Failed to parse plugin names from JSON" |
| exit 1 |
| fi |
| else |
| |
| PLUGINS=() |
| for plugin_dir in plugins/*/; do |
| if [ -d "$plugin_dir" ] && [ -f "$plugin_dir/go.mod" ]; then |
| plugin_name=$(basename "$plugin_dir") |
| PLUGINS+=("$plugin_name") |
| fi |
| done |
| fi |
|
|
| if [ ${#PLUGINS[@]} -eq 0 ]; then |
| echo "βοΈ No plugins to test" |
| exit 0 |
| fi |
|
|
| echo "π Testing ${#PLUGINS[@]} plugins:" |
| for p in "${PLUGINS[@]}"; do |
| echo " β’ $p" |
| done |
|
|
| FAILED_PLUGINS=() |
| SUCCESS_COUNT=0 |
| OVERALL_EXIT_CODE=0 |
|
|
| |
| for plugin in "${PLUGINS[@]}"; do |
| echo "" |
| echo "π Testing plugin: $plugin" |
| |
| PLUGIN_DIR="plugins/$plugin" |
| |
| if [ ! -d "$PLUGIN_DIR" ]; then |
| echo "β οΈ Warning: Plugin directory not found: $PLUGIN_DIR (skipping)" |
| continue |
| fi |
| |
| if [ ! -f "$PLUGIN_DIR/go.mod" ]; then |
| echo "βΉοΈ No go.mod found for $plugin, skipping tests" |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) |
| continue |
| fi |
| |
| cd "$PLUGIN_DIR" |
| |
| |
| echo "π¨ Validating plugin build..." |
| if ! go build ./...; then |
| echo "β Build failed for plugin: $plugin" |
| FAILED_PLUGINS+=("$plugin") |
| OVERALL_EXIT_CODE=1 |
| cd ../.. |
| continue |
| fi |
| |
| |
| if go list ./... | grep -q .; then |
| |
| if [ "$plugin" = "governance" ]; then |
| echo "π§ͺ Running governance plugin tests..." |
| |
| |
| if go test -v -timeout 20m -coverprofile=coverage.txt -coverpkg=./... ./...; then |
| echo "β
Tests passed for: $plugin" |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) |
| else |
| echo "β Tests failed for: $plugin" |
| FAILED_PLUGINS+=("$plugin") |
| OVERALL_EXIT_CODE=1 |
| fi |
| else |
| echo "π§ͺ Running plugin tests with coverage..." |
| if go test -v -timeout 20m -coverprofile=coverage.txt -coverpkg=./... ./...; then |
| echo "β
Tests passed for: $plugin" |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) |
| else |
| echo "β Tests failed for: $plugin" |
| FAILED_PLUGINS+=("$plugin") |
| OVERALL_EXIT_CODE=1 |
| fi |
| fi |
| |
| |
| if [ -n "${CODECOV_TOKEN:-}" ] && [ -f coverage.txt ]; then |
| echo "π Uploading coverage to Codecov..." |
| curl -Os https://uploader.codecov.io/latest/linux/codecov |
| chmod +x codecov |
| ./codecov -t "$CODECOV_TOKEN" -f coverage.txt -F "plugin-${plugin}" |
| rm -f codecov coverage.txt |
| else |
| rm -f coverage.txt |
| fi |
| else |
| echo "βΉοΈ No tests found for $plugin" |
| SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) |
| fi |
| |
| cd ../.. |
| done |
|
|
| |
| echo "" |
| echo "π Plugin Test Summary:" |
| echo " β
Successful: $SUCCESS_COUNT/${#PLUGINS[@]}" |
| echo " β Failed: ${#FAILED_PLUGINS[@]}" |
|
|
| if [ ${#FAILED_PLUGINS[@]} -gt 0 ]; then |
| echo " Failed plugins: ${FAILED_PLUGINS[*]}" |
| echo "β Plugin tests completed with failures" |
| exit $OVERALL_EXIT_CODE |
| else |
| echo " π All plugin tests passed!" |
| echo "β
Plugin tests completed successfully" |
| fi |
|
|