github.com/hyperledger/aries-framework-go@v0.3.2/scripts/check_unit.sh (about) 1 #!/bin/bash 2 # 3 # Copyright SecureKey Technologies Inc. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 set -e 8 9 echo "Running $0" 10 11 GO_TEST_CMD="go test" 12 13 go generate ./... 14 ROOT=$(pwd) 15 touch "$ROOT"/coverage.out 16 17 amend_coverage_file () { 18 if [ -f profile.out ]; then 19 cat profile.out >> "$ROOT"/coverage.out 20 rm profile.out 21 fi 22 } 23 24 # First argument is the exit code. 25 # Second argument is the command that was run. 26 check_exit_code () { 27 if [ "$1" -ne 0 ] && [ "$1" -ne 1 ]; then 28 echo "error: '${2}' returned ${1}, but either 0 or 1 was expected." 29 30 # There's no easy way to print the error message on the screen without temporary files, 31 # so we ask the user to check manually 32 echo "Try running '${2}' manually to see the full error message." 33 34 exit 1 35 fi 36 } 37 38 # docker rm returns 1 if the container isn't found. This is OK and expected, so we suppress it. 39 # Any return status other than 0 or 1 is unusual and so we exit. 40 remove_docker_containers () { 41 DOCKER_KILL_EXIT_CODE=0 42 docker kill AriesMongoDBStorageTest >/dev/null 2>&1 || DOCKER_KILL_EXIT_CODE=$? 43 docker kill AriesEDVStorageTest >/dev/null 2>&1 || DOCKER_KILL_EXIT_CODE=$? 44 45 check_exit_code $DOCKER_KILL_EXIT_CODE "docker kill AriesMongoDBStorageTest" 46 check_exit_code $DOCKER_KILL_EXIT_CODE "docker kill AriesEDVStorageTest" 47 48 DOCKER_RM_EXIT_CODE=0 49 docker rm AriesMongoDBStorageTest >/dev/null 2>&1 || DOCKER_RM_EXIT_CODE=$? 50 docker rm AriesEDVStorageTest >/dev/null 2>&1 || DOCKER_RM_EXIT_CODE=$? 51 52 check_exit_code $DOCKER_RM_EXIT_CODE "docker rm AriesMongoDBStorageTest" 53 check_exit_code $DOCKER_RM_EXIT_CODE "docker rm AriesEDVStorageTest" 54 } 55 56 # Running aries-framework-go unit test 57 PKGS=$(go list github.com/hyperledger/aries-framework-go/pkg/... 2> /dev/null | grep -v /mocks | grep -v /aries-js-worker) 58 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 59 amend_coverage_file 60 61 # Running aries-agent-rest unit test 62 cd cmd/aries-agent-rest 63 PKGS=$(go list github.com/hyperledger/aries-framework-go/cmd/aries-agent-rest/... 2> /dev/null | grep -v /mocks) 64 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 65 amend_coverage_file 66 cd ../.. 67 68 # Running storageutil unit tests 69 cd component/storageutil 70 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/storageutil/... 2> /dev/null) 71 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 72 amend_coverage_file 73 cd ../.. 74 75 # Running storage/leveldb unit tests 76 cd component/storage/leveldb/ 77 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/storage/leveldb/... 2> /dev/null) 78 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 79 amend_coverage_file 80 cd ../../.. 81 82 # Running kmscrypto unit tests 83 cd component/kmscrypto 84 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/kmscrypto/... 2> /dev/null) 85 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 86 amend_coverage_file 87 cd ../.. 88 89 # Running log unit tests 90 cd component/log 91 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/log/... 2> /dev/null) 92 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 93 amend_coverage_file 94 cd ../.. 95 96 # Running models unit tests 97 cd component/models 98 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/models/... 2> /dev/null) 99 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m 100 amend_coverage_file 101 cd ../.. 102 103 if [ "$SKIP_DOCKER" = true ]; then 104 echo "Skipping edv unit tests" 105 else 106 # Running storage/edv unit tests 107 . "$ROOT"/scripts/start_edv_test_docker_images.sh 108 109 cd component/storage/edv 110 PKGS=$(go list github.com/hyperledger/aries-framework-go/component/storage/edv/... 2> /dev/null) 111 GO_TEST_EXIT_CODE=0 112 $GO_TEST_CMD $PKGS -count=1 -race -coverprofile=profile.out -covermode=atomic -timeout=10m || GO_TEST_EXIT_CODE=$? 113 if [ $GO_TEST_EXIT_CODE -ne 0 ]; then 114 docker kill CouchDBStoreTest >/dev/null 115 docker kill MySQLStoreTest >/dev/null 116 remove_docker_containers 117 118 exit $GO_TEST_EXIT_CODE 119 fi 120 121 amend_coverage_file 122 123 docker kill AriesMongoDBStorageTest >/dev/null 124 docker kill AriesEDVStorageTest >/dev/null 125 remove_docker_containers 126 fi 127 128 129 cd "$ROOT" || exit