@@ -22,9 +22,12 @@ export GOLANGCI_LINT_CACHE=$(shell echo $${GOLANGCI_LINT_CACHE:-$$GOPATH/cache})
22
22
23
23
GOTAGS = "containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_ostree_stub"
24
24
25
+ UNITTEST_OPTS = -tags=$(GOTAGS ) -count=1 -v ./cmd/... ./pkg/... ./lib/...
26
+
25
27
all : binaries
26
28
27
29
.PHONY : clean test test-unit test-e2e verify update install-tools
30
+
28
31
# Remove build artifaces
29
32
# Example:
30
33
# make clean
@@ -46,16 +49,27 @@ image:
46
49
test : test-unit test-e2e
47
50
48
51
# Unit tests only (no active cluster required)
49
- test-unit :
50
- CGO_ENABLED=0 go test -tags=$(GOTAGS ) -count=1 -v ./cmd/... ./pkg/... ./lib/...
52
+ test-unit : install-go-junit-report
53
+ ifdef ARTIFACT_DIR
54
+ CGO_ENABLED=0 go test -coverprofile=mco-unit-test-coverage.out $(UNITTEST_OPTS) | ./hack/test-with-junit.sh $(@)
55
+ go tool cover -html=mco-unit-test-coverage.out -o mco-unit-test-coverage.html
56
+ # Move the test coverage report into ARTIFACT_DIR only when it is not the same as our current dir
57
+ # This enables test coverage analysis to be collected locally by running:
58
+ # $ ARTIFACT_DIR="$PWD" make test-unit
59
+ if [[ "${PWD}" != "${ARTIFACT_DIR}" ]]; then \
60
+ mv mco-unit-test-coverage.out mco-unit-test-coverage.html "${ARTIFACT_DIR}"; \
61
+ fi
62
+ else
63
+ CGO_ENABLED=0 go test $(UNITTEST_OPTS)
64
+ endif
51
65
52
66
# Run the code generation tasks.
53
67
# Example:
54
68
# make update
55
69
update :
56
70
hack/update-codegen.sh
57
71
hack/update-templates.sh
58
-
72
+
59
73
go-deps :
60
74
go mod tidy
61
75
go mod vendor
@@ -64,14 +78,42 @@ go-deps:
64
78
chmod +x ./vendor/k8s.io/code-generator/generate-groups.sh
65
79
chmod +x ./vendor/k8s.io/code-generator/generate-internal-groups.sh
66
80
67
- install-tools :
81
+ SETUP_ENVTEST := $(shell command -v setup-envtest 2> /dev/null)
82
+ install-setup-envtest :
83
+ ifdef SETUP_ENVTEST
84
+ @echo "Found setup-envtest"
85
+ else
86
+ @echo "Installing setup-envtest"
87
+ go install -mod= sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
88
+ endif
89
+
90
+ GO_JUNIT_REPORT := $(shell command -v go-junit-report 2> /dev/null)
91
+ install-go-junit-report :
92
+ ifdef GO_JUNIT_REPORT
93
+ @echo "Found go-junit-report"
94
+ go-junit-report --version
95
+ else
96
+ @echo "Installing go-junit-report"
97
+ go install -mod= github.com/jstemmer/go-junit-report@latest
98
+ endif
99
+
100
+ GOLANGCI_LINT := $(shell command -v golangci-lint 2> /dev/null)
101
+ install-golangci-lint :
102
+ ifdef GOLANGCI_LINT
103
+ @echo "Found golangci-lint"
104
+ golangci-lint --version
105
+ else
106
+ @echo "Installing golangci-lint"
68
107
GO111MODULE=on go build -o $(GOPATH)/bin/golangci-lint ./vendor/github.com/golangci/golangci-lint/cmd/golangci-lint
108
+ endif
109
+
110
+ install-tools : install-golangci-lint install-setup-envtest install-go-junit-report
69
111
70
112
# Run verification steps
71
113
# Example:
72
114
# make verify
73
115
verify : install-tools
74
- golangci-lint run --build-tags= $(GOTAGS )
116
+ ./hack/ golangci-lint.sh $(GOTAGS )
75
117
hack/verify-codegen.sh
76
118
hack/verify-templates.sh
77
119
@@ -101,16 +143,11 @@ Dockerfile.rhel7: Dockerfile Makefile
101
143
sed -e s,org/openshift/release,org/ocp/builder, -e s,/openshift/origin-v4.0:base,/ocp/4.0:base, < $< ) > $@ .tmp && mv $@ .tmp $@
102
144
103
145
# This was copied from https://github.com/openshift/cluster-image-registry-operator
104
- test-e2e :
105
- go test -tags=$(GOTAGS ) -failfast -timeout 110m -v$$ {WHAT:+ -run=" $$ WHAT" } ./test/e2e/
106
-
107
- test-e2e-single-node :
108
- go test -tags=$(GOTAGS ) -failfast -timeout 110m -v$$ {WHAT:+ -run=" $$ WHAT" } ./test/e2e-single-node/
146
+ test-e2e : install-go-junit-report
147
+ go test -tags=$(GOTAGS ) -failfast -timeout 110m -v$$ {WHAT:+ -run=" $$ WHAT" } ./test/e2e/ | ./hack/test-with-junit.sh $(@ )
109
148
110
- bootstrap -e2e:
111
- ./hack/bootstrap- e2e-test.sh
149
+ test -e2e-single-node : install-go-junit-report
150
+ go test -tags= $( GOTAGS ) -failfast -timeout 110m -v $$ {WHAT:+ -run= " $$ WHAT " } ./test/ e2e-single-node/ | ./hack/ test-with-junit .sh $( @ )
112
151
113
- bootstrap-e2e-local :
114
- # Use GOTAGS to exclude the default CGO implementation of signatures, which is not used by MCO
115
- # but dragged in by containers/image/signature
116
- CGO_ENABLED=0 go test -tags=$(GOTAGS ) -v$$ {WHAT:+ -run=" $$ WHAT" } ./test/e2e-bootstrap/
152
+ bootstrap-e2e : install-go-junit-report install-setup-envtest
153
+ CGO_ENABLED=0 go test -tags=$(GOTAGS ) -v$$ {WHAT:+ -run=" $$ WHAT" } ./test/e2e-bootstrap/ | ./hack/test-with-junit.sh $(@ )
0 commit comments