Skip to content

Commit 0b08db2

Browse files
authored
[chore][Makefile] Add with-cover targets for integration tests (#6144)
* [chore][Makefile] Add with-cover targets for integration tests * Update Makefile * Update .github/workflows/integration-test.yml * Update .github/workflows/integration-test.yml * Update .github/workflows/integration-test.yml * Update .github/workflows/integration-test.yml * Update Makefile
1 parent ea2797f commit 0b08db2

File tree

2 files changed

+91
-24
lines changed

2 files changed

+91
-24
lines changed

.github/workflows/integration-test.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ jobs:
230230
if: matrix.PROFILE == 'integration'
231231
- run: redis-cli set tempkey tempvalue
232232
if: matrix.PROFILE == 'integration'
233-
- name: Run Integration Test
233+
- name: Run Integration Test With Cover
234234
run: |
235235
set -o pipefail
236-
target="integration-test"
236+
target="integration-test-with-cover"
237237
if [[ "${{ matrix.PROFILE }}" = "smartagent" ]]; then
238-
target="smartagent-integration-test"
238+
target="smartagent-integration-test-with-cover"
239239
fi
240240
make $target 2>&1 | tee $TEST_OUTPUT
241241
exit_status=${PIPESTATUS[0]}
@@ -309,12 +309,12 @@ jobs:
309309
if: matrix.PROFILE == 'integration'
310310
- run: redis-cli set tempkey tempvalue
311311
if: matrix.PROFILE == 'integration'
312-
- name: Run Integration Test
312+
- name: Run Integration Test With Cover
313313
run: |
314314
set -o pipefail
315-
target="integration-test"
315+
target="integration-test-with-cover"
316316
if [[ "${{ matrix.PROFILE }}" = "smartagent" ]]; then
317-
target="smartagent-integration-test"
317+
target="smartagent-integration-test-with-cover"
318318
fi
319319
make $target 2>&1 | tee $TEST_OUTPUT
320320
exit_status=${PIPESTATUS[0]}
@@ -385,8 +385,8 @@ jobs:
385385
- run: docker load -i ./docker-otelcol/${{ matrix.ARCH }}/image.tar
386386
- run: ln -sf otelcol_linux_${{ matrix.ARCH }} ./bin/otelcol
387387
- run: chmod a+x ./bin/*
388-
- name: Run ${{ matrix.SERVICE }} Discovery Integration Test
389-
run: make integration-test-${{ matrix.SERVICE }}-discovery
388+
- name: Run ${{ matrix.SERVICE }} Discovery Integration Test With Cover
389+
run: make integration-test-${{ matrix.SERVICE }}-discovery-with-cover
390390
env:
391391
SPLUNK_OTEL_COLLECTOR_IMAGE: 'otelcol:latest'
392392

@@ -447,8 +447,8 @@ jobs:
447447
- name: Load Docker image in kind
448448
run: |
449449
kind load docker-image otelcol:latest --name kind
450-
- name: Run ${{ matrix.SERVICE }} Discovery Kubernetes Integration Test
451-
run: KUBECONFIG=$HOME/.kube/config SKIP_TEARDOWN=true make integration-test-${{ matrix.SERVICE }}-discovery-k8s
450+
- name: Run ${{ matrix.SERVICE }} Discovery Kubernetes Integration Test With Cover
451+
run: KUBECONFIG=$HOME/.kube/config SKIP_TEARDOWN=true make integration-test-${{ matrix.SERVICE }}-discovery-k8s-with-cover
452452
- name: Print logs
453453
if: failure()
454454
run: |

Makefile

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ BUILD_INFO=-ldflags "${BUILD_X1} ${BUILD_X2}"
3131
BUILD_INFO_TESTS=-ldflags "-X $(BUILD_INFO_IMPORT_PATH_TESTS).Version=$(VERSION)"
3232
CGO_ENABLED?=0
3333

34+
# This directory is used in tests hold code coverage results.
35+
# It's mounted on docker containers which then write code coverage
36+
# results to it, making coverage profiles available on the host after tests.
37+
# 777 privileges are important to allow docker container write
38+
# access to host dir.
39+
MAKE_TEST_COVER_DIR=mkdir -m 777 -p $(TEST_COVER_DIR)
40+
3441
JMX_METRIC_GATHERER_RELEASE=$(shell cat packaging/jmx-metric-gatherer-release.txt)
3542
SKIP_COMPILE=false
3643
ARCH?=amd64
@@ -82,57 +89,118 @@ for-all-target: $(ALL_MODS)
8289
integration-vet:
8390
@set -e; cd tests && go vet -tags integration,testutilsintegration,zeroconfig,testutils ./... && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) -tags testutils,testutilsintegration -v -timeout 5m -count 1 ./...
8491

92+
.PHONY: integration-test-target
93+
integration-test-target:
94+
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=$(TARGET) -v -timeout 5m -count 1 ./...
95+
96+
.PHONY: integration-test-cover-target
97+
integration-test-cover-target:
98+
@set -e; $(MAKE_TEST_COVER_DIR) && cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=$(TARGET) -v -timeout 5m -count 1 ./... $(COVER_TESTING_INTEGRATION_OPTS)
99+
$(GOCMD) tool covdata textfmt -i=$(TEST_COVER_DIR) -o ./$(TARGET)-coverage.txt
100+
85101
.PHONY: integration-test
86102
integration-test:
87-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=integration -v -timeout 5m -count 1 ./...
103+
@make integration-test-target TARGET='integration'
104+
105+
.PHONY: integration-test-with-cover
106+
integration-test-with-cover:
107+
@make integration-test-cover-target TARGET='integration'
88108

89109
.PHONY: integration-test-mongodb-discovery
90110
integration-test-mongodb-discovery:
91-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_mongodb -v -timeout 5m -count 1 ./...
111+
@make integration-test TARGET='discovery_integration_mongodb'
112+
113+
.PHONY: integration-test-mongodb-discovery-with-cover
114+
integration-test-mongodb-discovery-with-cover:
115+
@make integration-test-cover-target TARGET='discovery_integration_mongodb'
92116

93117
.PHONY: integration-test-mysql-discovery
94118
integration-test-mysql-discovery:
95-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_mysql -v -timeout 5m -count 1 ./...
119+
@make integration-test TARGET='discovery_integration_mysql'
120+
121+
.PHONY: integration-test-mysql-discovery-with-cover
122+
integration-test-mysql-discovery-with-cover:
123+
@make integration-test-cover-target TARGET='discovery_integration_mysql'
96124

97125
.PHONY: integration-test-kafkametrics-discovery
98126
integration-test-kafkametrics-discovery:
99-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_kafkametrics -v -timeout 5m -count 1 ./...
127+
@make integration-test TARGET='discovery_integration_kafkametrics'
128+
129+
.PHONY: integration-test-kafkametrics-discovery-with-cover
130+
integration-test-kafkametrics-discovery-with-cover:
131+
@make integration-test-cover-target TARGET='discovery_integration_kafkametrics'
100132

101133
.PHONY: integration-test-jmx/cassandra-discovery
102134
integration-test-jmx/cassandra-discovery:
103-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_jmx -v -timeout 5m -count 1 ./...
135+
@make integration-test TARGET='discovery_integration_jmx'
136+
137+
.PHONY: integration-test-jmx/cassandra-discovery-with-cover
138+
integration-test-jmx/cassandra-discovery-with-cover:
139+
@make integration-test-cover-target TARGET='discovery_integration_jmx'
104140

105141
.PHONY: integration-test-apache-discovery
106142
integration-test-apache-discovery:
107-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_apachewebserver -v -timeout 5m -count 1 ./...
143+
@make integration-test TARGET='discovery_integration_apachewebserver'
144+
145+
.PHONY: integration-test-apache-discovery-with-cover
146+
integration-test-apache-discovery-with-cover:
147+
@make integration-test-cover-target TARGET='discovery_integration_apachewebserver'
108148

109149
.PHONY: integration-test-envoy-discovery
110150
integration-test-envoy-discovery:
111-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_envoy -v -timeout 5m -count 1 ./...
151+
@make integration-test TARGET='discovery_integration_envoy'
152+
153+
.PHONY: integration-test-envoy-discovery-with-cover
154+
integration-test-envoy-discovery-with-cover:
155+
@make integration-test-cover-target TARGET='discovery_integration_envoy'
112156

113157
.PHONY: integration-test-nginx-discovery
114158
integration-test-nginx-discovery:
115-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_nginx -v -timeout 5m -count 1 ./...
159+
@make integration-test TARGET='discovery_integration_nginx'
160+
161+
.PHONY: integration-test-nginx-discovery-with-cover
162+
integration-test-nginx-discovery-with-cover:
163+
@make integration-test-cover-target TARGET='discovery_integration_nginx'
116164

117165
.PHONY: integration-test-redis-discovery
118166
integration-test-redis-discovery:
119-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_redis -v -timeout 5m -count 1 ./...
167+
@make integration-test TARGET='discovery_integration_redis'
168+
169+
.PHONY: integration-test-redis-discovery-with-cover
170+
integration-test-redis-discovery-with-cover:
171+
@make integration-test-cover-target TARGET='discovery_integration_redis'
120172

121173
.PHONY: integration-test-oracledb-discovery
122174
integration-test-oracledb-discovery:
123-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_oracledb -v -timeout 5m -count 1 ./...
175+
@make integration-test TARGET='discovery_integration_oracledb'
176+
177+
.PHONY: integration-test-oracledb-discovery-with-cover
178+
integration-test-oracledb-discovery-with-cover:
179+
@make integration-test-cover-target TARGET='discovery_integration_oracledb'
124180

125181
.PHONY: smartagent-integration-test
126182
smartagent-integration-test:
127-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=smartagent_integration -v -timeout 5m -count 1 ./...
183+
@make integration-test TARGET='smartagent_integration'
184+
185+
.PHONY: smartagent-integration-test-with-cover
186+
smartagent-integration-test-with-cover:
187+
@make integration-test-cover-target TARGET='smartagent_integration'
128188

129189
.PHONY: integration-test-envoy-discovery-k8s
130190
integration-test-envoy-discovery-k8s:
131-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_envoy_k8s -v -timeout 5m -count 1 ./...
191+
@make integration-test TARGET='discovery_integration_envoy_k8s'
192+
193+
.PHONY: integration-test-envoy-discovery-k8s-with-cover
194+
integration-test-envoy-discovery-k8s-with-cover:
195+
@make integration-test-cover-target TARGET='discovery_integration_envoy_k8s'
132196

133197
.PHONY: integration-test-istio-discovery-k8s
134198
integration-test-istio-discovery-k8s:
135-
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_istio_k8s -v -timeout 15m -count 1 ./...
199+
@make integration-test TARGET='discovery_integration_istio_k8s'
200+
201+
.PHONY: integration-test-istio-discovery-k8s-with-cover
202+
integration-test-istio-discovery-k8s-with-cover:
203+
@make integration-test-cover-target TARGET='discovery_integration_istio_k8s'
136204

137205
.PHONY: gotest-with-codecov
138206
gotest-with-codecov:
@@ -181,7 +249,6 @@ else
181249
$(LINK_CMD) otelcol_$(GOOS)_$(GOARCH)$(EXTENSION) ./bin/otelcol$(EXTENSION)
182250
endif
183251

184-
185252
.PHONY: migratecheckpoint
186253
migratecheckpoint:
187254
go generate ./...

0 commit comments

Comments
 (0)