Skip to content

Commit

Permalink
Add coverage evidence to the project
Browse files Browse the repository at this point in the history
Configure CI to collect coverage and integrate with coveralls.io
service.

Move plugin packages out of `pkg` package, as they aren't
exportable as library and their presence conflicts with
`-coverpkg=./...` cover parameter.

Add Makefile rules for merging coverage profiles from multiple
sources, as tests are usually run by `make test-pkg` and
`make test-controllers`.

Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Apr 7, 2022
1 parent 2e6003b commit 78d6185
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go 1.17+
uses: actions/setup-go@v2
with:
go-version: ^1.17
go-version: 1.17.8

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Set up Go 1.17+
uses: actions/setup-go@v2
with:
go-version: ^1.17
go-version: 1.17.8

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -42,3 +42,9 @@ jobs:
- name: test controllers on opensfhit
run: CLUSTER_TYPE=openshift make test-controllers

- name: merge test coverage
run: make merge-test-coverage

- uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: cover.out
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,27 @@ test-e2e-validation-only:
test-e2e: generate vet manifests skopeo
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); source hack/env.sh; go test ./test/e2e/... -timeout 60m -coverprofile cover.out -v
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); source hack/env.sh; go test ./test/e2e/... -timeout 60m --covermode count coverprofile cover.out -v

test-e2e-k8s: export NAMESPACE=sriov-network-operator
test-e2e-k8s: test-e2e

test-%: generate vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./$*/... -coverprofile cover.out -v
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./$*/... -coverprofile cover-$*.out -coverpkg ./... -v

# deploy-setup-k8s: export NAMESPACE=sriov-network-operator
# deploy-setup-k8s: export ENABLE_ADMISSION_CONTROLLER=false
# deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin
# test-e2e-k8s: test-e2e

gocovmerge: ## Download gocovmerge locally if necessary.
go install -mod=readonly github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest

merge-test-coverage: gocovmerge
gocovmerge cover-*.out > cover.out

deploy-wait:
hack/deploy-wait.sh

Expand Down
2 changes: 1 addition & 1 deletion hack/build-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ mkdir -p ${BIN_PATH}
CGO_ENABLED=1

echo "Building ${REPO}/pkg/plugins (${VERSION_OVERRIDE})"
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/pkg/plugins/$1
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/plugins/$1
#CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -buildmode=plugin -gcflags='all=-N -l' -ldflags "${GLDFLAGS} -s -w" ${GOFLAGS} -o ${BIN_PATH}/plugins/$1_plugin.so ${REPO}/pkg/plugins/$1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 78d6185

Please sign in to comment.