Skip to content

Commit

Permalink
Updated the code with the coverage information.
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 12, 2022
1 parent 9d4b236 commit 1f6363d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Upload Coverage Report
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
with:
files: /tmp/rekor-merged.cov
files: /tmp/rekor-merged.cov,/tmp/pkg-rekor-merged.cov
flags: e2etests

sharding-e2e:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ trillianServerImagerefs
trillianSignerImagerefs
cosign.*
signature
rekor.pub
rekor.pub
25 changes: 22 additions & 3 deletions pkg/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
# limitations under the License.

set -e
testdir=$(dirname "$0")

rm -f /tmp/rekor-*.cov
echo "installing gocovmerge"
make gocovmerge
docker kill $(docker ps -q) || true
echo "starting services"
docker-compose up -d
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d --force-recreate --build

echo "building CLI and server"
# set the path to the root of the repo
dir=$(git rev-parse --show-toplevel)
go build -o rekor-cli ./cmd/rekor-cli
go build -o rekor-server ./cmd/rekor-server
go test -c ./cmd/rekor-cli -o rekor-cli -cover -covermode=count -coverpkg=./...
go test -c ./cmd/rekor-server -o rekor-server -covermode=count -coverpkg=./...

count=0
echo -n "waiting up to 120 sec for system to start"
Expand Down Expand Up @@ -56,3 +60,18 @@ if docker-compose logs --no-color | grep -q "panic: runtime error:" ; then
docker-compose logs --no-color > /tmp/docker-compose.log
exit 1
fi

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
# 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')"
23 changes: 20 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func Run(t *testing.T, stdin, cmd string, arg ...string) string {
t.Log(string(b))
t.Fatal(err)
}

return string(b)
return stripCoverageOutput(string(b))
}

func RunCli(t *testing.T, arg ...string) string {
Expand All @@ -98,7 +97,7 @@ func RunCliStdout(t *testing.T, arg ...string) string {
t.Log(string(b))
t.Fatal(err)
}
return string(b)
return stripCoverageOutput(string(b))
}

func RunCliErr(t *testing.T, arg ...string) string {
Expand Down Expand Up @@ -128,6 +127,14 @@ func rekorServer() string {
return "http://localhost:3000"
}

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

func stripCoverageOutput(out string) string {
return strings.Split(strings.Split(out, "PASS")[0], "FAIL")[0]
}

func readFile(t *testing.T, p string) string {
b, err := ioutil.ReadFile(p)
if err != nil {
Expand All @@ -136,6 +143,16 @@ func readFile(t *testing.T, p string) string {
return strings.TrimSpace(string(b))
}

func randomSuffix(n int) string {
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}

func randomData(t *testing.T, n int) []byte {
t.Helper()
rand.Seed(time.Now().UnixNano())
Expand Down

0 comments on commit 1f6363d

Please sign in to comment.