Debian Codegraph @

scripts/cov.sh

raw
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 # Fail fast by checking if we can run gocovmerge
21 gocovmerge
22 if [[ $? != 0 ]]; then
23 echo "Unable to run gocovmerge"
24 exit 1
25 fi
26
27 rm -rf ./cov
28 mkdir cov
29 #
30 # Since it is difficult to get a full run without a flapper, do not use `-failfast`.
31 # It is better to have one flapper or two and still get the report than have
32 # to re-run the whole code coverage. One or two failed tests should not affect
33 # so much the code coverage.
34 #
35 # However, we need to take into account that if there is a panic in one test, all
36 # other tests in that package will not run, which then would cause the code coverage
37 # to drastically be lowered. In that case, we don't want the code coverage to be
38 # uploaded.
39 #
40 go test -v -covermode=atomic -coverprofile=./cov/conf.out ./conf -timeout=1h -tags=skip_no_race_tests
41 check_file "conf" "conf.out"
42 go test -v -covermode=atomic -coverprofile=./cov/internal.out ./internal/ldap -timeout=1h -tags=skip_no_race_tests
43 check_file "internal" "internal.out"
44 go test -v -covermode=atomic -coverprofile=./cov/log.out ./logger -timeout=1h -tags=skip_no_race_tests
45 check_file "logger" "log.out"
46 go test -v -covermode=atomic -coverprofile=./cov/server_avl.out ./server/avl -timeout=1h -tags=skip_no_race_tests
47 check_file "server_avl" "server_avl.out"
48 go test -v -covermode=atomic -coverprofile=./cov/server.out ./server -timeout=1h -tags=skip_no_race_tests
49 check_file "server" "server.out"
50 go test -v -covermode=atomic -coverprofile=./cov/test.out -coverpkg=./server ./test -timeout=1h -tags=skip_no_race_tests
51 check_file "test" "test.out"
52
53 # At this point, if that fails, we want the caller to know about the failure.
54 set -e
55 gocovmerge ./cov/*.out > acc.out
56 rm -rf ./cov
57
58 # If no argument passed, launch a browser to see the results.
59 if [[ $1 == "" ]]; then
60 go tool cover -html=acc.out
61 fi
62 set +e