Skip to content

Commit

Permalink
Combine integration and unit test coverage (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk authored Apr 10, 2023
1 parent b1630c4 commit 2e309b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: '1.20'
- name: Build
run: go build -cover -v
- name: Prepare coverage
- name: Build and test with integration coverage
run: |
echo "GOCOVERDIR=$(pwd)/coverage" >> $GITHUB_ENV
mkdir -p coverage
- name: Test
run: go test -v ./...
- name: Merge and convert coverage
go build -cover -v
mkdir -p coverage/integration
GOCOVERDIR=$(pwd)/coverage/integration go test ./... -v -count=1
- name: Rebuild and test with unit coverage
run: |
go tool covdata textfmt \
-i=$GOCOVERDIR \
-o coverage/coverage.txt
go build -v
go test ./... -count=1 -coverprofile=coverage/unit-coverage.txt
- name: Process coverage
# Coverage is simple text files, so we can combine the integration
# and unit test coverage by simply appending the latter with the
# first line skipped.
run: |
go tool covdata textfmt -i=coverage/integration -o coverage/integration-coverage.txt
cp coverage/integration-coverage.txt coverage/coverage.txt
tail -n +2 coverage/unit-coverage.txt >> coverage/coverage.txt
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./coverage/
files: ./coverage/coverage.txt
26 changes: 18 additions & 8 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
set -e

# Run this from the repository root, not from scripts!
export GOCOVERDIR=$(pwd)/coverage

COVERAGE=$(pwd)/coverage
INTEGRATION_COVERAGE=$COVERAGE/integration

echo "Rebuilding with coverage enabled..."
go clean
go build -cover

echo "Running tests with coverage written to $GOCOVERDIR..."
rm -rf $GOCOVERDIR
mkdir $GOCOVERDIR
go test ./... -count=1
rm -rf $COVERAGE
mkdir -p $INTEGRATION_COVERAGE

echo "Running integration tests with coverage written to $INTEGRATION_COVERAGE..."
GOCOVERDIR=$INTEGRATION_COVERAGE go test ./... -count=1

echo "Running unit tests with coverage written to $UNIT_COVERAGE..."
go test ./... -count=1 -coverprofile=$COVERAGE/unit-coverage.txt

echo "Converting integration coverage format..."
go tool covdata textfmt -i=$INTEGRATION_COVERAGE -o $COVERAGE/integration-coverage.txt

echo "Converting coverage formats..."
go tool covdata textfmt -i=$GOCOVERDIR -o $GOCOVERDIR/coverage.txt
echo "Merging coverage..."
cp $COVERAGE/integration-coverage.txt $COVERAGE/coverage.txt
tail -n +2 $COVERAGE/unit-coverage.txt >> $COVERAGE/coverage.txt

echo "Opening coverage..."
go tool cover -html=$GOCOVERDIR/coverage.txt
go tool cover -html=$COVERAGE/coverage.txt

0 comments on commit 2e309b4

Please sign in to comment.