github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/unit-test/run.sh (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 9 set -e 10 ARCH=`uname -m` 11 12 #check job type, do patch set specific unit test when job is verify 13 if [ "$JOB_TYPE" = "VERIFY" ]; then 14 15 cd $GOPATH/src/github.com/hyperledger/fabric/ 16 17 #figure out what packages should be tested for uncommitted changes 18 # first check for uncommitted changes 19 TEST_PKGS=$(git diff --name-only HEAD * | grep .go$ | grep -v ^vendor/ \ 20 | grep -v ^build/ | sed 's%/[^/]*$%/%'| sort -u \ 21 | awk '{print "github.com/hyperledger/fabric/"$1"..."}') 22 23 if [ -z "$TEST_PKGS" ]; then 24 # next check for changes in the latest commit - typically this will 25 # be for CI only, but could also handle a committed change before 26 # pushing to Gerrit 27 TEST_PKGS=$(git diff-tree --no-commit-id --name-only -r $(git log -2 \ 28 --pretty=format:"%h") | grep .go$ | grep -v ^vendor/ | grep -v ^build/ \ 29 | sed 's%/[^/]*$%/%'| sort -u | \ 30 awk '{print "github.com/hyperledger/fabric/"$1"..."}') 31 fi 32 33 #only run the test when test pkgs is not empty 34 if [[ ! -z "$TEST_PKGS" ]]; then 35 echo "Testing packages:" 36 echo $TEST_PKGS 37 # use go test -cover as this is much more efficient than gocov 38 time go test -cover -ldflags "$GO_LDFLAGS" $TEST_PKGS -p 1 -timeout=20m 39 else 40 echo "Nothing changed in unit test!!!" 41 fi 42 43 else 44 45 #check to see if TEST_PKGS is set else use default (all packages) 46 TEST_PKGS=${TEST_PKGS:-github.com/hyperledger/fabric/...} 47 echo -n "Obtaining list of tests to run for the following packages: ${TEST_PKGS}" 48 49 # Some examples don't play nice with `go test` 50 PKGS=`go list ${TEST_PKGS} 2> /dev/null | \ 51 grep -v /vendor/ | \ 52 grep -v /build/ | \ 53 grep -v /bccsp/mocks | \ 54 grep -v /bddtests | \ 55 grep -v /orderer/mocks | \ 56 grep -v /orderer/sample_clients | \ 57 grep -v /common/mocks | \ 58 grep -v /common/ledger/testutil | \ 59 grep -v /core/mocks | \ 60 grep -v /core/testutil | \ 61 grep -v /core/ledger/testutil | \ 62 grep -v /core/ledger/kvledger/example | \ 63 grep -v /core/ledger/kvledger/marble_example | \ 64 grep -v /core/deliverservice/mocks | \ 65 grep -v /core/scc/samplesyscc | \ 66 grep -v /test | \ 67 grep -v /examples` 68 69 if [ x$ARCH == xppc64le -o x$ARCH == xs390x ] 70 then 71 PKGS=`echo $PKGS | sed 's@'github.com/hyperledger/fabric/core/chaincode/platforms/java/test'@@g'` 72 PKGS=`echo $PKGS | sed 's@'github.com/hyperledger/fabric/core/chaincode/platforms/java'@@g'` 73 fi 74 75 echo " DONE!" 76 77 echo "Running tests..." 78 #go test -cover -ldflags "$GO_LDFLAGS" $PKGS -p 1 -timeout=20m 79 gocov test -ldflags "$GO_LDFLAGS" $PKGS -p 1 -timeout=20m | gocov-xml > report.xml 80 fi