Skip to content

Commit

Permalink
Fixed the coverage issues.
Browse files Browse the repository at this point in the history
Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan committed Oct 18, 2022
1 parent 1f6363d commit 8b50a00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/e2e-test.sh
Expand Up @@ -17,7 +17,7 @@
set -e
testdir=$(dirname "$0")

rm -f /tmp/rekor-*.cov
rm -f /tmp/pkg-rekor-*.cov
echo "installing gocovmerge"
make gocovmerge
docker kill $(docker ps -q) || true
Expand Down Expand Up @@ -65,13 +65,13 @@ echo "generating code coverage"
curl -X GET 0.0.0.0:2345/kill
sleep 5

if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/rekor-server.cov ; then
if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov /tmp/pkg-rekor-server.cov ; then
# failed to copy code coverage report from server
echo "Failed to retrieve server code coverage report"
docker-compose logs --no-color > /tmp/docker-compose.log
exit 1
fi

# merging coverage reports and filtering out /pkg/generated from final report
hack/tools/bin/gocovmerge /tmp/rekor-*.cov | grep -v "/pkg/generated/" > /tmp/rekor-merged.cov
echo "code coverage $(go tool cover -func=/tmp/rekor-merged.cov | grep -E '^total\:' | sed -E 's/\s+/ /g')"
hack/tools/bin/gocovmerge /tmp/pkg-rekor-*.cov | grep -v "/pkg/generated/" > /tmp/pkg-rekor-merged.cov
echo "code coverage $(go tool cover -func=/tmp/pkg-rekor-merged.cov | grep -E '^total\:' | sed -E 's/\s+/ /g')"
7 changes: 5 additions & 2 deletions pkg/util/util.go
Expand Up @@ -40,7 +40,6 @@ var (
)

func init() {

p := os.Getenv("REKORTMPDIR")
if p != "" {
cli = path.Join(p, cli)
Expand All @@ -57,6 +56,7 @@ func OutputContains(t *testing.T, output, sub string) {

func Run(t *testing.T, stdin, cmd string, arg ...string) string {
t.Helper()
arg = append([]string{coverageFlag()}, arg...)
c := exec.Command(cmd, arg...)
if stdin != "" {
c.Stdin = strings.NewReader(stdin)
Expand All @@ -75,6 +75,7 @@ func Run(t *testing.T, stdin, cmd string, arg ...string) string {

func RunCli(t *testing.T, arg ...string) string {
t.Helper()
arg = append([]string{coverageFlag()}, arg...)
arg = append(arg, rekorServerFlag())
// use a blank config file to ensure no collision
if os.Getenv("REKORTMPDIR") != "" {
Expand All @@ -85,6 +86,7 @@ func RunCli(t *testing.T, arg ...string) string {

func RunCliStdout(t *testing.T, arg ...string) string {
t.Helper()
arg = append([]string{coverageFlag()}, arg...)
arg = append(arg, rekorServerFlag())
c := exec.Command(cli, arg...)

Expand All @@ -102,6 +104,7 @@ func RunCliStdout(t *testing.T, arg ...string) string {

func RunCliErr(t *testing.T, arg ...string) string {
t.Helper()
arg = append([]string{coverageFlag()}, arg...)
arg = append(arg, rekorServerFlag())
// use a blank config file to ensure no collision
if os.Getenv("REKORTMPDIR") != "" {
Expand All @@ -128,7 +131,7 @@ func rekorServer() string {
}

func coverageFlag() string {
return "-test.coverprofile=/tmp/rekor-cli." + randomSuffix(8) + ".cov"
return "-test.coverprofile=/tmp/pkg-rekor-cli." + randomSuffix(8) + ".cov"
}

func stripCoverageOutput(out string) string {
Expand Down

0 comments on commit 8b50a00

Please sign in to comment.