github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/esti/scripts/runner.sh (about)

     1  #!/bin/bash
     2  
     3  cd "$(dirname "$0")" || exit
     4  . set_env_vars.sh
     5  
     6  LAKEFS_LOG=$(mktemp --suffix=.log --tmpdir lakefs_XXX)
     7  TEST_LOG=$(mktemp --suffix=.log --tmpdir lakefs_tests_XXX)
     8  RUN_RESULT=2
     9  
    10  trap cleanup EXIT
    11  
    12  cleanup() {
    13    pkill lakefs
    14    if [ $RUN_RESULT == 0 ]; then
    15      echo "Tests successful, cleaning up logs files"
    16      rm $LAKEFS_LOG
    17      rm $TEST_LOG
    18    elif [ $RUN_RESULT == 1 ]; then
    19      echo "Tests failed! See logs for more information: $LAKEFS_LOG $TEST_LOG"
    20    fi
    21  }
    22  
    23  invalid_option() {
    24    echo "Error: Invalid option"
    25    Help
    26  }
    27  
    28  help() {
    29    echo "Local system tests execution"
    30    echo
    31    echo "Syntax: runner [-h|r]"
    32    echo "options:"
    33    echo "h     Print this Help."
    34    echo "r     Runs the given process [lakefs | tests | all]."
    35    echo
    36  }
    37  
    38  wait_for_lakefs_ready() {
    39    echo "Waiting for lakeFS ready"
    40    until curl --output /dev/null --silent --head --fail localhost:8000/_health; do
    41        printf '.'
    42        sleep 1
    43    done
    44    echo "lakeFS is ready"
    45  }
    46  
    47  run_tests() {
    48    echo "Run Tests (logs at $TEST_LOG)"
    49    go test -v ../../esti --args --system-tests --use-local-credentials --skip=".*GC" "$@" | tee "$TEST_LOG"
    50    return "${PIPESTATUS[0]}"
    51  }
    52  
    53  run_lakefs() {
    54    echo "Run LakeFS (logs at $LAKEFS_LOG)"
    55    lakefs run -c lakefs.yaml | tee "$LAKEFS_LOG"
    56  }
    57  
    58  run_all() {
    59    run_lakefs &
    60  
    61    wait_for_lakefs_ready
    62  
    63    run_tests "$@"
    64    RUN_RESULT=$?
    65    return $RUN_RESULT		# restore failure (the previous line succeeds in sh)
    66  }
    67  
    68  # Get the options
    69  while getopts ":hr:" option; do
    70    case $option in
    71    h) # Display Help
    72      help
    73      exit
    74      ;;
    75    r) # Run
    76      run=$OPTARG
    77      shift 2
    78      if [ "$run" == "test" ]; then
    79        run_tests "$@"
    80      elif [ "$run" == "lakefs" ]; then
    81        run_lakefs
    82      elif [ "$run" == "all" ]; then
    83        run_all "$@"
    84      else
    85        invalid_option
    86      fi
    87      exit
    88      ;;
    89    \?) # Invalid option
    90      invalid_option
    91      exit
    92      ;;
    93    esac
    94  done
    95  
    96  help # No arguments passed