get.pme.sh/pnats@v0.0.0-20240304004023-26bb5a137ed0/scripts/cov.sh (about) 1 #!/bin/bash 2 # Run from directory above via ./scripts/cov.sh 3 4 check_file () { 5 # If the content of the file is simply "mode: atomic", then it means that the 6 # code coverage did not complete due to a panic in one of the tests. 7 if [[ $(cat ./cov/$2) == "mode: atomic" ]]; then 8 echo "#############################################" 9 echo "## Code coverage for $1 package failed ##" 10 echo "#############################################" 11 exit 1 12 fi 13 } 14 15 # Do not globally set the -e flag because we don't a flapper to prevent the push to coverall. 16 17 export GO111MODULE="on" 18 19 go install github.com/wadey/gocovmerge@latest 20 21 rm -rf ./cov 22 mkdir cov 23 # 24 # Since it is difficult to get a full run without a flapper, do not use `-failfast`. 25 # It is better to have one flapper or two and still get the report than have 26 # to re-run the whole code coverage. One or two failed tests should not affect 27 # so much the code coverage. 28 # 29 # However, we need to take into account that if there is a panic in one test, all 30 # other tests in that package will not run, which then would cause the code coverage 31 # to drastically be lowered. In that case, we don't want the code coverage to be 32 # uploaded. 33 # 34 go test -v -covermode=atomic -coverprofile=./cov/conf.out ./conf -timeout=1h -tags=skip_no_race_tests 35 check_file "conf" "conf.out" 36 go test -v -covermode=atomic -coverprofile=./cov/internal.out ./internal/ldap -timeout=1h -tags=skip_no_race_tests 37 check_file "internal" "internal.out" 38 go test -v -covermode=atomic -coverprofile=./cov/log.out ./logger -timeout=1h -tags=skip_no_race_tests 39 check_file "logger" "log.out" 40 go test -v -covermode=atomic -coverprofile=./cov/server_avl.out ./server/avl -timeout=1h -tags=skip_no_race_tests 41 check_file "server_avl" "server_avl.out" 42 go test -v -covermode=atomic -coverprofile=./cov/server.out ./server -timeout=1h -tags=skip_no_race_tests 43 check_file "server" "server.out" 44 go test -v -covermode=atomic -coverprofile=./cov/test.out -coverpkg=./server ./test -timeout=1h -tags=skip_no_race_tests 45 check_file "test" "test.out" 46 47 # At this point, if that fails, we want the caller to know about the failure. 48 set -e 49 gocovmerge ./cov/*.out > acc.out 50 rm -rf ./cov 51 52 # If no argument passed, launch a browser to see the results. 53 if [[ $1 == "" ]]; then 54 go tool cover -html=acc.out 55 fi 56 set +e