github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/test.sh (about)

     1  #!/bin/bash
     2  # Copyright 2017 Google Inc.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     https://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  
    17  # Get absolute path to symlink's directory
    18  set +e # Do not exit if readlink errors out
    19  SCRIPT_DIR="$(/usr/bin/dirname "$(readlink -e "${ARGV0}" 2>/dev/null)")"
    20  # Exit on error.
    21  set -e
    22  if [[ -z "${SCRIPT_DIR}" || "${SCRIPT_DIR}" == '.' ]]; then
    23    SCRIPT_DIR="$(/usr/bin/dirname "${BASH_SOURCE[0]}")"
    24    if [[ -z "${SCRIPT_DIR}" ]]; then
    25      /bin/echo 'Failed to resolve script directory.'
    26      exit 1
    27    fi
    28  fi
    29  # Go to this script's directory.
    30  cd "${SCRIPT_DIR}"
    31  
    32  readonly TEST_SHS='src/server/grpcservice/client/testing/client_test.sh'
    33  
    34  function test_single_sh {
    35    local readonly SH=${1}
    36  
    37    OUT=$("${SH}" 2>&1)
    38  
    39    if [ "$?" -ne 0 ]; then
    40      /bin/echo "FAIL ${SH}"
    41      /bin/echo "${OUT}"
    42      return 1
    43    fi
    44  
    45    /bin/echo "PASS ${SH}"
    46  }
    47  
    48  function pretty_echo {
    49    /bin/echo '---'
    50    /bin/echo "${@}"
    51    /bin/echo '---'
    52  }
    53  
    54  RC=0
    55  
    56  pretty_echo 'Building prerequisites for Go tests.'
    57  go build -o ./src/e2etesting/frr_master_server_main/frr_master_server_main{,.go}
    58  go build -o ./src/e2etesting/balancer/balancer{,.go}
    59  go build -o ./src/client/daemonservice/testclient/testclient{,.go}
    60  go build -o ./src/client/socketservice/testclient/testclient{,.go}
    61  go build -o ./src/server/grpcservice/client/testing/tester{,.go}
    62  cd ..
    63  # Required for src/e2etesting/localtesting.
    64  go build -o ./cmd/fleetspeak_config/fleetspeak_config{,.go}
    65  go build -o ./cmd/fleetspeak_client/fleetspeak_client{,.go}
    66  go build -o ./cmd/fleetspeak_server/fleetspeak_server{,.go}
    67  cd -
    68  
    69  pretty_echo 'Executing Go tests.'
    70  go test -race --timeout 2.5m ./... || RC=1
    71  
    72  pretty_echo 'Executing Python tests.'
    73  pytest -v ../fleetspeak_python || RC=2
    74  
    75  pretty_echo 'Executing Bash tests.'
    76  for s in ${TEST_SHS}; do
    77    test_single_sh "${s}" || RC=3
    78  done
    79  
    80  exit "${RC}"