-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoverage.sh
executable file
·46 lines (36 loc) · 1.54 KB
/
coverage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
set -x
# Protobuf schema registry schema evolution tests register the same message type
# in the same package. These are compiled in the same binary (the test), and by default
# proto panics in such a situation. Setting this envvar ignores that check
export GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore
# golang packages that will be used for either testing or will be assessed for coverage
pck1=github.com/zillow/zkafka/v2
pck2=$pck1/test
topdir=$(pwd)
# binary result filepaths
root_res=$topdir/root.res
source_res=$topdir/source.res
# go cover formatted files
root_out=$topdir/root.out
source_out=$topdir/source.out
cover_out=$topdir/cover.out
function quit() {
echo "Error in coverage.sh. Stopping processing";
exit;
}
# change to example directory for execution (because it uses hardcoded filepaths, and the testable
# examples don't work when executed outside of that directory
go test --tags=evolution_test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" $pck1
# convert binary to go formatted
go tool test2json -t "$root_res" -test.v -test.coverprofile "$root_out"
go test --tags=evolution_test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" $pck2
go tool test2json -t "$source_res" -test.v -test.coverprofile "$source_out"
# delete aggregate file
rm "$cover_out"
# combine the results (the first line should be omitted on subsequent appends)
cat "$root_out" >> "$cover_out"
tail -n+2 "$source_out" >> "$cover_out"
# print aggregated results
go tool cover -func="$cover_out"
go tool cover -html="$cover_out" -o cover.html