github.com/mkimuram/operator-sdk@v0.7.1-0.20190410172100-52ad33a4bda0/hack/lib/test_lib.sh (about) 1 #!/usr/bin/env bash 2 3 source hack/lib/common.sh 4 5 function listPkgs() { 6 go list ./cmd/... ./pkg/... ./test/... | grep -v generated 7 } 8 9 function listFiles() { 10 # make it work with composed gopath 11 for gopath in ${GOPATH//:/ }; do 12 if [[ "$(pwd)" =~ "$gopath" ]]; then 13 GOPATH="$gopath" 14 break 15 fi 16 done 17 # pipeline is much faster than for loop 18 listPkgs | xargs -I {} find "${GOPATH}/src/{}" -name '*.go' | grep -v generated 19 } 20 21 #=================================================================== 22 # FUNCTION trap_add () 23 # 24 # Purpose: prepends a command to a trap 25 # 26 # - 1st arg: code to add 27 # - remaining args: names of traps to modify 28 # 29 # Example: trap_add 'echo "in trap DEBUG"' DEBUG 30 # 31 # See: http://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal 32 #=================================================================== 33 function trap_add() { 34 trap_add_cmd=$1; shift || fatal "${FUNCNAME} usage error" 35 new_cmd= 36 for trap_add_name in "$@"; do 37 # Grab the currently defined trap commands for this trap 38 existing_cmd=`trap -p "${trap_add_name}" | awk -F"'" '{print $2}'` 39 40 # Define default command 41 [ -z "${existing_cmd}" ] && existing_cmd="echo exiting @ `date`" 42 43 # Generate the new command 44 new_cmd="${trap_add_cmd};${existing_cmd}" 45 46 # Assign the test 47 trap "${new_cmd}" "${trap_add_name}" || \ 48 fatal "unable to add to trap ${trap_add_name}" 49 done 50 }