github.com/hyperledger/fabric-ca@v2.0.0-alpha.0.20201120210307-7b4f34729db1+incompatible/scripts/run_unit_tests (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  
     7  set -euo pipefail
     8  
     9  excluded=(
    10      "/integration"
    11      "/ldap"
    12      "/test/fabric-ca-load-tester$"
    13  )
    14  
    15  # join array elements by the specified string
    16  join_by() {
    17      local IFS="$1"; shift
    18      [ "$#" -eq 0 ] && return 0
    19      echo "$*"
    20  }
    21  
    22  list_and_filter() {
    23      local filter
    24      filter=$(join_by '|' "${excluded[@]}")
    25      if [ -n "$filter" ]; then
    26          go list "$@" 2>/dev/null | grep -Ev "${filter}" || true
    27      else
    28          go list "$@" 2>/dev/null
    29      fi
    30  }
    31  
    32  run_tests() {
    33      GO_TAGS=${GO_TAGS:-}
    34      [ -n "$GO_TAGS" ] && echo "Testing with $GO_TAGS..."
    35  
    36      time go test -tags "$GO_TAGS" -cover -timeout 15m -p 1 "$@"
    37  }
    38  
    39  main() {
    40      local packages=()
    41      while IFS= read -r pkg; do
    42          packages+=("$pkg");
    43      done < <(list_and_filter "github.com/hyperledger/fabric-ca/...")
    44  
    45      run_tests "${packages[@]}"
    46      GO_TAGS="pkcs11" run_tests "${packages[@]}"
    47  }
    48  
    49  main