Skip to content

Commit

Permalink
Merge pull request #336 from suleymanakbas91/codecov
Browse files Browse the repository at this point in the history
OCPVE-286: Introduce code coverage tooling
  • Loading branch information
openshift-merge-robot authored May 4, 2023
2 parents 24e61fc + 351a9c7 commit 166b452
Show file tree
Hide file tree
Showing 35 changed files with 90 additions and 19 deletions.
32 changes: 32 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
codecov:
notify:
require_ci_to_pass: no
wait_for_ci: no

coverage:
precision: 2
round: down
range: "20...100"

status:
project: no
patch: no
changes: no

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no

ignore:
- "test/**/*"
- "**/mocks"
- "**/zz_generated*.go"
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ UNAME := $(shell uname)
OPERATOR_VERSION ?= 0.0.1

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22
ENVTEST_K8S_VERSION = 1.26.0

OPERATOR_SDK_VERSION ?= 1.23.0
RBAC_PROXY_IMG ?= gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
Expand Down Expand Up @@ -146,21 +146,24 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

godeps-update: ## Run go mod tidy and go mod vendor.
go mod tidy && go mod vendor

verify: ## Verify go formatting and generated files.
hack/verify-gofmt.sh
hack/verify-deps.sh
hack/verify-bundle.sh
hack/verify-generated.sh

godeps-update: ## Run go mod tidy and go mod vendor.
go mod tidy && go mod vendor
test: manifests generate envtest godeps-update ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -coverprofile=coverage.out `go list ./... | grep -v "e2e"`
ifeq ($(OPENSHIFT_CI), true)
hack/publish-codecov.sh
endif

run: manifests generate ## Run a controller from your host.
run: manifests generate ## Run the Operator from your host.
go run ./main.go

test: manifests generate envtest godeps-update ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -cover `go list ./... | grep -v "e2e"`

##@ Build

IMAGE_BUILD_CMD ?= $(shell command -v docker 2>&1 >/dev/null && echo docker || echo podman)
Expand Down Expand Up @@ -287,8 +290,8 @@ DISK_INSTALL ?= false
# Build and run e2e tests.
e2e-test: ginkgo ## Build and run e2e tests.
@echo "build and run e2e tests"
cd e2e && $(GINKGO) build
cd e2e && ./e2e.test --lvm-catalog-image=$(CATALOG_IMG) --lvm-subscription-channel=$(SUBSCRIPTION_CHANNEL) --lvm-operator-install=$(LVM_OPERATOR_INSTALL) --lvm-operator-uninstall=$(LVM_OPERATOR_UNINSTALL) --disk-install=$(DISK_INSTALL) -ginkgo.v
cd test/e2e && $(GINKGO) build
cd test/e2e && ./e2e.test --lvm-catalog-image=$(CATALOG_IMG) --lvm-subscription-channel=$(SUBSCRIPTION_CHANNEL) --lvm-operator-install=$(LVM_OPERATOR_INSTALL) --lvm-operator-uninstall=$(LVM_OPERATOR_UNINSTALL) --disk-install=$(DISK_INSTALL) -ginkgo.v

##@ Tools

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases"),
filepath.Join("..", "e2e", "testdata")},
filepath.Join("..", "test", "e2e", "testdata")},
ErrorIfCRDPathMissing: true,
CRDInstallOptions: envtest.CRDInstallOptions{
CleanUpAfterUse: true,
Expand Down Expand Up @@ -107,7 +107,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).ToNot(HaveOccurred())

// Create the primary namespace to be used by some of the tests
// Create the primary namespace to be used by some tests
testNamespace := &corev1.Namespace{}
testNamespace.Name = testLvmClusterNamespace
Expect(k8sClient.Create(ctx, testNamespace)).Should(Succeed())
Expand Down
3 changes: 1 addition & 2 deletions controllers/vgmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ func TestVGManagerEnsureCreated(t *testing.T) {
},
}

for i, testCase := range testTable {
t.Logf("TestCase #%d: %q", i, testCase.desc)
for _, testCase := range testTable {
lvmcluster := &lvmv1alpha1.LVMCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "testcluster",
Expand Down
43 changes: 43 additions & 0 deletions hack/publish-codecov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(git rev-parse --show-toplevel)
CI_SERVER_URL=https://prow.svc.ci.openshift.org/view/gcs/origin-ci-test
COVER_PROFILE=${COVER_PROFILE:-coverage.out}
JOB_TYPE=${JOB_TYPE:-"local"}

# Configure the git refs and job link based on how the job was triggered via prow
if [[ "${JOB_TYPE}" == "presubmit" ]]; then
echo "detected PR code coverage job for #${PULL_NUMBER}"
REF_FLAGS="-P ${PULL_NUMBER} -C ${PULL_PULL_SHA}"
JOB_LINK="${CI_SERVER_URL}/pr-logs/pull/${REPO_OWNER}_${REPO_NAME}/${PULL_NUMBER}/${JOB_NAME}/${BUILD_ID}"
elif [[ "${JOB_TYPE}" == "postsubmit" ]]; then
echo "detected branch code coverage job for ${PULL_BASE_REF}"
REF_FLAGS="-B ${PULL_BASE_REF} -C ${PULL_BASE_SHA}"
JOB_LINK="${CI_SERVER_URL}/logs/${JOB_NAME}/${BUILD_ID}"
elif [[ "${JOB_TYPE}" == "local" ]]; then
echo "coverage report available at ${COVER_PROFILE}"
exit 0
else
echo "${JOB_TYPE} jobs not supported" >&2
exit 1
fi

# Configure certain internal codecov variables with values from prow.
export CI_BUILD_URL="${JOB_LINK}"
export CI_BUILD_ID="${JOB_NAME}"
export CI_JOB_ID="${BUILD_ID}"

if [[ "${JOB_TYPE}" != "local" ]]; then
if [[ -z "${ARTIFACT_DIR:-}" ]] || [[ ! -d "${ARTIFACT_DIR}" ]] || [[ ! -w "${ARTIFACT_DIR}" ]]; then
echo '${ARTIFACT_DIR} must be set for non-local jobs, and must point to a writable directory' >&2
exit 1
fi
curl -sS https://codecov.io/bash -o "${ARTIFACT_DIR}/codecov.sh"
bash <(cat "${ARTIFACT_DIR}/codecov.sh") -Z -K -f "${COVER_PROFILE}" -r "${REPO_OWNER}/${REPO_NAME}" ${REF_FLAGS}
else
bash <(curl -s https://codecov.io/bash) -Z -K -f "${COVER_PROFILE}" -r "${REPO_OWNER}/${REPO_NAME}" ${REF_FLAGS}
fi
6 changes: 0 additions & 6 deletions pkg/vgmanager/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestNotReadOnly(t *testing.T) {
{label: "tc invalid string", device: internal.BlockDevice{ReadOnly: "test"}, expected: true, expectErr: true},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[notReadOnly](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand All @@ -42,7 +41,6 @@ func TestNotSuspended(t *testing.T) {
{label: "tc running", device: internal.BlockDevice{State: "running"}, expected: true, expectErr: false},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[notSuspended](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand All @@ -60,7 +58,6 @@ func TestNoFilesystemSignature(t *testing.T) {
{label: "tc swap", device: internal.BlockDevice{FSType: "swap"}, expected: false, expectErr: false},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[noFilesystemSignature](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand All @@ -77,7 +74,6 @@ func TestNoChildren(t *testing.T) {
{label: "tc no child", device: internal.BlockDevice{Name: "dev2", Children: []internal.BlockDevice{}}, expected: true, expectErr: false},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[noChildren](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand All @@ -94,7 +90,6 @@ func TestIsUsableDeviceType(t *testing.T) {
{label: "tc Disk", device: internal.BlockDevice{Name: "dev2", Type: "disk"}, expected: true, expectErr: false},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[usableDeviceType](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand All @@ -115,7 +110,6 @@ func TestNoBiosBootInPartLabel(t *testing.T) {
{label: "tc 6", device: internal.BlockDevice{Name: "dev6", PartLabel: "BOOT"}, expected: false, expectErr: false},
}
for _, tc := range testcases {
t.Log("Test case : " + tc.label)
result, err := FilterMap[noBiosBootInPartLabel](tc.device, nil)
assert.Equal(t, tc.expected, result)
if tc.expectErr {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 166b452

Please sign in to comment.