From 8b50a00e8be53697ee4f6eff0aec20fbd698ef13 Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Tue, 18 Oct 2022 09:15:28 -0500 Subject: [PATCH] Fixed the coverage issues. Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- pkg/e2e-test.sh | 8 ++++---- pkg/util/util.go | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/e2e-test.sh b/pkg/e2e-test.sh index 3f4bde4f2..744ad6f6d 100755 --- a/pkg/e2e-test.sh +++ b/pkg/e2e-test.sh @@ -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 @@ -65,7 +65,7 @@ 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 @@ -73,5 +73,5 @@ if ! docker cp $(docker ps -aqf "name=rekor_rekor-server"):go/rekor-server.cov / 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')" diff --git a/pkg/util/util.go b/pkg/util/util.go index 6daa036eb..e313d4304 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -40,7 +40,6 @@ var ( ) func init() { - p := os.Getenv("REKORTMPDIR") if p != "" { cli = path.Join(p, cli) @@ -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) @@ -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") != "" { @@ -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...) @@ -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") != "" { @@ -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 {