Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

2.3 KB
Raw Blame
#!/usr/bin/env bash
# Agent-friendly test runner for Metabase backend (Clojure) tests.
#
# Differences from a normal `clj -X:dev:test` run:
#   - Puts dev/test on the test path (:dev/test), so the project-level checks under
#     dev/test/metabase/core are runnable with :only.
#   - Uses HAWK_MODE=cli/ci so eftest.report.pretty is used instead of the
#     progress-bar reporter.  Failures print inline as they happen.
#   - Strips ANSI escape codes from output so results are plain text.
#   - Filters Maven download noise and reflection warnings.
#
# Usage:
#   bin/test-agent :only '[metabase.foo-test]'
#   bin/test-agent :only '[metabase.foo-test/some-test]'
#   bin/test-agent --oss :only '[metabase.foo-test]'   # run without EE extensions
#   bin/test-agent --drivers=mysql,h2,postgres :module enterprise/workspaces  # run driver tests
#   bin/test-agent                          # runs all tests (rarely what you want)
#
# Options:
#   --oss             Run without enterprise extensions (uses :oss:oss-dev instead of :ee:ee-dev)
#   --drivers=LIST    Add driver aliases (:drivers:drivers-dev) and set DRIVERS=LIST.
#                     LIST is a comma-separated list of driver names, e.g. mysql,h2,postgres.
#
# Any extra arguments are forwarded directly to the clojure test command.
# The :test alias uses port 0 (OS-assigned random port) so parallel runs never collide.

set -euo pipefail

export HAWK_MODE=cli/ci

# Parse our own flags; forward everything else to clojure.
INCLUDE_OSS=false
INCLUDE_DRIVERS=false
DRIVERS_VAL=""
args=()
for arg in "$@"; do
  if [[ "$arg" == "--oss" ]]; then
    INCLUDE_OSS=true
  elif [[ "$arg" == --drivers=* ]]; then
    INCLUDE_DRIVERS=true
    DRIVERS_VAL="${arg#--drivers=}"
  else
    args+=("$arg")
  fi
done

if $INCLUDE_OSS; then
  ALIASES=":dev:dev/test:ci:test:oss:oss-dev"
else
  ALIASES=":dev:dev/test:ee:ee-dev:test"
fi

if $INCLUDE_DRIVERS; then
  ALIASES="${ALIASES}:drivers:drivers-dev"
  export DRIVERS="$DRIVERS_VAL"
fi

# Filter noise and strip ANSI escape sequences
clean_output() {
  grep -v '^Downloading: ' \
  | grep -v '^Reflection warning,' \
  | grep -v '^Excluding directory' \
  | grep -v '^Looking for test namespaces in directory' \
  | sed $'s/\033[\[(][0-9;]*[A-Za-z]//g; s/\033[^[]*//g'
}

exec clojure -X"${ALIASES}" "${args[@]}" 2>&1 | clean_output