Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 16 additions & 58 deletions e2e/compat/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,110 +13,68 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Get the monorepo root
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

log_info() {
echo -e "${GREEN}[INFO]${NC} $*"
}

log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $*"
}
# Load shared utilities
# shellcheck source=../lib/common.sh
source "$SCRIPT_DIR/../lib/common.sh"

# Check if setup was completed
check_setup() {
if [ ! -f "$REPO_ROOT/.e2e-setup-complete" ]; then
if ! load_setup_config "$REPO_ROOT"; then
log_error "Setup not complete! Please run e2e/compat/setup.sh first."
return 1
fi

# Load setup configuration
source "$REPO_ROOT/.e2e-setup-complete"

# Export OLD_JMP if set
export OLD_JMP="${OLD_JMP:-}"

# Verify critical components are still running
if ! kubectl get namespace "$JS_NAMESPACE" &> /dev/null; then
log_error "Namespace $JS_NAMESPACE not found. Please run e2e/compat/setup.sh again."
if ! verify_namespace; then
log_error "Please run e2e/compat/setup.sh again."
return 1
fi

log_info "Setup verified"
return 0
}

# Setup environment for bats
setup_bats_env() {
local LOCAL_BATS_LIB="$REPO_ROOT/.bats/lib"

if [ -d "$LOCAL_BATS_LIB" ]; then
export BATS_LIB_PATH="$LOCAL_BATS_LIB:${BATS_LIB_PATH:-}"
log_info "Set BATS_LIB_PATH to local libraries: $BATS_LIB_PATH"
else
log_warn "Local bats libraries not found at $LOCAL_BATS_LIB"
fi
}

# Run the tests
run_tests() {
log_info "Running jumpstarter compatibility e2e tests..."

cd "$REPO_ROOT"

# Activate virtual environment
if [ -f python/.venv/bin/activate ]; then
source python/.venv/bin/activate
else
log_error "Virtual environment not found. Please run e2e/compat/setup.sh first."
activate_venv "python/.venv" || {
log_error "Please run e2e/compat/setup.sh first."
exit 1
fi
}

# Use insecure GRPC for testing
export JUMPSTARTER_GRPC_INSECURE=1

# Export variables for bats
export JS_NAMESPACE="${JS_NAMESPACE}"
export ENDPOINT="${ENDPOINT}"

# Setup bats environment
setup_bats_env

COMPAT_TEST="${COMPAT_TEST:-old-controller}"
log_info "Running compat test: $COMPAT_TEST"

local label_filter=""
case "$COMPAT_TEST" in
old-controller)
bats -x --show-output-of-passing-tests --verbose-run \
"$SCRIPT_DIR/tests-old-controller.bats"
label_filter="old-controller"
;;
old-client)
export OLD_JMP
bats -x --show-output-of-passing-tests --verbose-run \
"$SCRIPT_DIR/tests-old-client.bats"
label_filter="old-client"
;;
*)
log_error "Unknown COMPAT_TEST: $COMPAT_TEST (expected 'old-controller' or 'old-client')"
exit 1
;;
esac

run_ginkgo "$SCRIPT_DIR/../test" "$label_filter"
}

# Main execution
main() {
export JS_NAMESPACE="${JS_NAMESPACE:-jumpstarter-lab}"
export E2E_TEST_NS="${E2E_TEST_NS:-jumpstarter-lab}"

log_info "=== Jumpstarter Compatibility E2E Test Runner ==="
log_info "Test: ${COMPAT_TEST:-old-controller}"
log_info "Namespace: $JS_NAMESPACE"
log_info "Namespace: $E2E_TEST_NS"
log_info "Repository Root: $REPO_ROOT"
echo ""

Expand Down
9 changes: 1 addition & 8 deletions e2e/compat/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,11 @@ setup_test_environment() {
# Write setup configuration
cat > "$REPO_ROOT/.e2e-setup-complete" <<EOF
ENDPOINT=$ENDPOINT
JS_NAMESPACE=$JS_NAMESPACE
E2E_TEST_NS=$JS_NAMESPACE
REPO_ROOT=$REPO_ROOT
SCRIPT_DIR=$SCRIPT_DIR
METHOD=$METHOD
BATS_LIB_PATH=${BATS_LIB_PATH:-}
EOF

# Add OLD_JMP if set (old-client scenario)
if [ -n "${OLD_JMP:-}" ]; then
echo "OLD_JMP=$OLD_JMP" >> "$REPO_ROOT/.e2e-setup-complete"
fi

log_info "Test environment ready"
}

Expand Down
84 changes: 84 additions & 0 deletions e2e/lib/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# Common utilities shared between e2e runner scripts.
# Source this file from run-e2e.sh and compat/run.sh.

# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

log_info() {
echo -e "${GREEN}[INFO]${NC} $*"
}

log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}

log_error() {
echo -e "${RED}[ERROR]${NC} $*"
}

# Check if running in CI
is_ci() {
[ -n "${CI:-}" ] || [ -n "${GITHUB_ACTIONS:-}" ]
}

# activate_venv activates the Python virtual environment.
activate_venv() {
local venv_path="${1:-python/.venv}"
if [ -f "$venv_path/bin/activate" ]; then
# shellcheck disable=SC1091
source "$venv_path/bin/activate"
else
log_error "Virtual environment not found at $venv_path."
return 1
fi
}

# load_setup_config loads the .e2e-setup-complete configuration file and
# exports common variables needed by the Go test suite.
load_setup_config() {
local repo_root="$1"

if [ ! -f "$repo_root/.e2e-setup-complete" ]; then
return 1
fi

# shellcheck disable=SC1091
source "$repo_root/.e2e-setup-complete"

export E2E_TEST_NS="${E2E_TEST_NS:-jumpstarter-lab}"
export ENDPOINT="${ENDPOINT:-}"
export REPO_ROOT="${repo_root}"
}

# verify_namespace checks that the test namespace exists in the cluster.
verify_namespace() {
local ns="${1:-$E2E_TEST_NS}"
if ! kubectl get namespace "$ns" &> /dev/null; then
log_error "Namespace $ns not found."
return 1
fi
}

# run_ginkgo runs the ginkgo test suite with the given label filter and
# optional extra flags.
run_ginkgo() {
local test_dir="$1"
shift
local label_filter="${1:-}"
shift || true

local flags=(-v --show-node-events --trace --timeout 30m)
if [ -n "$label_filter" ]; then
flags+=(--label-filter "$label_filter")
fi

cd "$test_dir"
go run github.com/onsi/ginkgo/v2/ginkgo \
"${flags[@]}" \
"$@" \
./...
}
Loading
Loading