Skip to content

Commit

Permalink
Code coverage. (#39)
Browse files Browse the repository at this point in the history
* Code coverage.

* Code coverage.

* Remove commands.
  • Loading branch information
cinar committed Jun 17, 2023
1 parent f5dfe90 commit 306675b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
run: go build -v ./...

- name: Go test
run: go test -v ./...


run: go test -v -coverprofile=coverage.out ./...

- name: Go coverage
env:
CODE_COVERAGE_THRESHOLD: 100
run: ./scripts/coverage.sh
25 changes: 25 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

COVERAGE_FILE=coverage.out

if [ -z "$CODE_COVERAGE_THRESHOLD" ]
then
echo "No code coverage threshold is set."
exit 0
fi

echo "Code coverage threshold ${CODE_COVERAGE_THRESHOLD}%"

if [ ! -e "$COVERAGE_FILE" ]
then
echo "Coverage file ${COVERAGE_FILE} is not found."
exit 1
fi

CODE_COVERAGE=$(go tool cover -func=coverage.out | grep "total:" | grep -E -o '[0-9]+\.[0-9]+')

if awk "BEGIN { exit !($CODE_COVERAGE < $CODE_COVERAGE_THRESHOLD)}"
then
echo "Current code coverage ${CODE_COVERAGE}% is below the ${CODE_COVERAGE_THRESHOLD}% threshold."
exit 1
fi
3 changes: 0 additions & 3 deletions test_helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !test
// +build !test

package checker

import "testing"
Expand Down

0 comments on commit 306675b

Please sign in to comment.