diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..46937e202 --- /dev/null +++ b/.codecov.yml @@ -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" diff --git a/Makefile b/Makefile index a47f71cfb..08d552f3c 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) @@ -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 diff --git a/controllers/lvmcluster_controller_test.go b/controllers/lvmcluster_controller_integration_test.go similarity index 100% rename from controllers/lvmcluster_controller_test.go rename to controllers/lvmcluster_controller_integration_test.go diff --git a/controllers/suite_test.go b/controllers/suite_test.go index c872ebf86..453835a8d 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -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, @@ -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()) diff --git a/controllers/vgmanager_test.go b/controllers/vgmanager_test.go index 2ecdc9a66..59c897198 100644 --- a/controllers/vgmanager_test.go +++ b/controllers/vgmanager_test.go @@ -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", diff --git a/hack/publish-codecov.sh b/hack/publish-codecov.sh new file mode 100755 index 000000000..7f0d553d6 --- /dev/null +++ b/hack/publish-codecov.sh @@ -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 diff --git a/pkg/vgmanager/filter_test.go b/pkg/vgmanager/filter_test.go index 17440acd9..8f7538783 100644 --- a/pkg/vgmanager/filter_test.go +++ b/pkg/vgmanager/filter_test.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/e2e/aws_disk.go b/test/e2e/aws_disk.go similarity index 100% rename from e2e/aws_disk.go rename to test/e2e/aws_disk.go diff --git a/e2e/common.go b/test/e2e/common.go similarity index 100% rename from e2e/common.go rename to test/e2e/common.go diff --git a/e2e/config.go b/test/e2e/config.go similarity index 100% rename from e2e/config.go rename to test/e2e/config.go diff --git a/e2e/disk_setup.go b/test/e2e/disk_setup.go similarity index 100% rename from e2e/disk_setup.go rename to test/e2e/disk_setup.go diff --git a/e2e/ephemeral_check.go b/test/e2e/ephemeral_check.go similarity index 100% rename from e2e/ephemeral_check.go rename to test/e2e/ephemeral_check.go diff --git a/e2e/helper.go b/test/e2e/helper.go similarity index 100% rename from e2e/helper.go rename to test/e2e/helper.go diff --git a/e2e/lvm_suite_test.go b/test/e2e/lvm_suite_test.go similarity index 100% rename from e2e/lvm_suite_test.go rename to test/e2e/lvm_suite_test.go diff --git a/e2e/lvmcluster.go b/test/e2e/lvmcluster.go similarity index 100% rename from e2e/lvmcluster.go rename to test/e2e/lvmcluster.go diff --git a/e2e/pvc_check.go b/test/e2e/pvc_check.go similarity index 100% rename from e2e/pvc_check.go rename to test/e2e/pvc_check.go diff --git a/e2e/setup_teardown.go b/test/e2e/setup_teardown.go similarity index 100% rename from e2e/setup_teardown.go rename to test/e2e/setup_teardown.go diff --git a/e2e/subscription.go b/test/e2e/subscription.go similarity index 100% rename from e2e/subscription.go rename to test/e2e/subscription.go diff --git a/e2e/testdata/ephemeral_tests/ephemeral-clone.yaml b/test/e2e/testdata/ephemeral_tests/ephemeral-clone.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/ephemeral-clone.yaml rename to test/e2e/testdata/ephemeral_tests/ephemeral-clone.yaml diff --git a/e2e/testdata/ephemeral_tests/ephemeral-snapshot-restore.yaml b/test/e2e/testdata/ephemeral_tests/ephemeral-snapshot-restore.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/ephemeral-snapshot-restore.yaml rename to test/e2e/testdata/ephemeral_tests/ephemeral-snapshot-restore.yaml diff --git a/e2e/testdata/ephemeral_tests/ephemeral-volume-snapshot.yaml b/test/e2e/testdata/ephemeral_tests/ephemeral-volume-snapshot.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/ephemeral-volume-snapshot.yaml rename to test/e2e/testdata/ephemeral_tests/ephemeral-volume-snapshot.yaml diff --git a/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-device.yaml b/test/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-device.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/pod-ephemeral-volume-device.yaml rename to test/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-device.yaml diff --git a/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-mount.yaml b/test/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-mount.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/pod-ephemeral-volume-mount.yaml rename to test/e2e/testdata/ephemeral_tests/pod-ephemeral-volume-mount.yaml diff --git a/e2e/testdata/ephemeral_tests/pod-volume-device-template.yaml b/test/e2e/testdata/ephemeral_tests/pod-volume-device-template.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/pod-volume-device-template.yaml rename to test/e2e/testdata/ephemeral_tests/pod-volume-device-template.yaml diff --git a/e2e/testdata/ephemeral_tests/pod-volume-mount-template.yaml b/test/e2e/testdata/ephemeral_tests/pod-volume-mount-template.yaml similarity index 100% rename from e2e/testdata/ephemeral_tests/pod-volume-mount-template.yaml rename to test/e2e/testdata/ephemeral_tests/pod-volume-mount-template.yaml diff --git a/e2e/testdata/pvc_tests/pod-volume-device-template.yaml b/test/e2e/testdata/pvc_tests/pod-volume-device-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/pod-volume-device-template.yaml rename to test/e2e/testdata/pvc_tests/pod-volume-device-template.yaml diff --git a/e2e/testdata/pvc_tests/pod-volume-mount-template.yaml b/test/e2e/testdata/pvc_tests/pod-volume-mount-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/pod-volume-mount-template.yaml rename to test/e2e/testdata/pvc_tests/pod-volume-mount-template.yaml diff --git a/e2e/testdata/pvc_tests/pvc-clone-template.yaml b/test/e2e/testdata/pvc_tests/pvc-clone-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/pvc-clone-template.yaml rename to test/e2e/testdata/pvc_tests/pvc-clone-template.yaml diff --git a/e2e/testdata/pvc_tests/pvc-snapshot-restore-template.yaml b/test/e2e/testdata/pvc_tests/pvc-snapshot-restore-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/pvc-snapshot-restore-template.yaml rename to test/e2e/testdata/pvc_tests/pvc-snapshot-restore-template.yaml diff --git a/e2e/testdata/pvc_tests/pvc-template.yaml b/test/e2e/testdata/pvc_tests/pvc-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/pvc-template.yaml rename to test/e2e/testdata/pvc_tests/pvc-template.yaml diff --git a/e2e/testdata/pvc_tests/volume-snapshot-template.yaml b/test/e2e/testdata/pvc_tests/volume-snapshot-template.yaml similarity index 100% rename from e2e/testdata/pvc_tests/volume-snapshot-template.yaml rename to test/e2e/testdata/pvc_tests/volume-snapshot-template.yaml diff --git a/e2e/testdata/pvc_tests/volume-snapshot.yaml b/test/e2e/testdata/pvc_tests/volume-snapshot.yaml similarity index 100% rename from e2e/testdata/pvc_tests/volume-snapshot.yaml rename to test/e2e/testdata/pvc_tests/volume-snapshot.yaml diff --git a/e2e/testdata/snapshot.storage.k8s.io_volumesnapshotclasses.yaml b/test/e2e/testdata/snapshot.storage.k8s.io_volumesnapshotclasses.yaml similarity index 100% rename from e2e/testdata/snapshot.storage.k8s.io_volumesnapshotclasses.yaml rename to test/e2e/testdata/snapshot.storage.k8s.io_volumesnapshotclasses.yaml diff --git a/e2e/utils.go b/test/e2e/utils.go similarity index 100% rename from e2e/utils.go rename to test/e2e/utils.go diff --git a/e2e/validation.go b/test/e2e/validation.go similarity index 100% rename from e2e/validation.go rename to test/e2e/validation.go