Skip to content

Commit

Permalink
1. Updated to use custom coverage script (integration tests off)
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartboyd119 committed Jul 23, 2024
1 parent a6f1362 commit c433bed
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ test-local: setup-test test-no-setup

.PHONY: cover
cover:
go test -v ./... -count=1 -coverprofile=cover.out -covermode atomic && \
go tool cover -html=cover.out -o cover.html
./coverage.sh

.PHONY: example-producer
example-producer:
Expand Down
17 changes: 3 additions & 14 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function quit() {
}
# change to example directory for execution (because it uses hardcoded filepaths, and the testable
# examples don't work when executed outside of that directory
go test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" -tags integration $pck1
go test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" $pck1
# convert binary to go formatted
go tool test2json -t "$root_res" -test.v -test.coverprofile "$root_out"

go test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" -tags integration $pck2
go test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" $pck2
go tool test2json -t "$source_res" -test.v -test.coverprofile "$source_out"

# delete aggregate file
Expand All @@ -38,15 +38,4 @@ tail -n+2 "$source_out" >> "$omni_out"

# print aggregated results
go tool cover -func="$omni_out"

# we need to create a cobertura.xml file (this is used for code coverage visualization)
# download the tool to convert gocover into covertura
go install github.com/boumenot/gocover-cobertura@latest
gocover-cobertura < $omni_out > coverage.tmp.xml
# the cobertura generated file has two issues. Its source array doesn't include the curdir and
# the class node filepaths aren't relative to the root.
# We'll run two commands
# 1. Remove the prefixed go.mod package name from filenames inside of the cobertura with a brute force replace with empty string
# 2. Add the workingdirectory to the sources array using a find replace (search for sources node, and replace with sources node but new workdir source nod)
pkg=gitlab.zgtools.net/devex/archetypes/gomods/zkafka
sed "s|$pkg/||" coverage.tmp.xml | sed "s|<sources>|<sources>\n<source>$(pwd)</source>|"> coverage.xml
go tool cover -html="$omni_out" -o cover.html

0 comments on commit c433bed

Please sign in to comment.