@@ -21,7 +21,7 @@ BENCHMARK_ARGS := -count=8
21
21
BENCHMARK_PACKAGE ?= ./...
22
22
BENCHMARK_FILTER ?= Bench
23
23
24
- GO_TEST_FLAG = ""
24
+ GO_TEST_FLAG =
25
25
ifdef TEST_COVERAGE
26
26
GO_TEST_FLAG = -covermode=atomic -coverprofile=build/TEST-go-fleet-server-coverage.cov
27
27
endif
@@ -44,6 +44,7 @@ DOCKER_IMAGE?=docker.elastic.co/fleet-server/fleet-server
44
44
45
45
46
46
PLATFORM_TARGETS =$(addprefix release-, $(PLATFORMS ) )
47
+ COVER_TARGETS =$(addprefix cover-, $(PLATFORMS ) )
47
48
COMMIT =$(shell git rev-parse --short HEAD)
48
49
NOW =$(shell date -u '+% Y-% m-% dT% H:% M:% SZ')
49
50
CMD_COLOR_ON =\033[32m\xE2\x9c\x93
@@ -75,10 +76,23 @@ local: ## - Build local binary for local environment (bin/fleet-server)
75
76
go build $(if $(DEV ) ,-tags="dev",) -gcflags=" ${GCFLAGS} " -ldflags=" ${LDFLAGS} " -o ./bin/fleet-server .
76
77
@printf " ${CMD_COLOR_ON} Binaries in ./bin/\n${CMD_COLOR_OFF} "
77
78
79
+ .PHONY : cover-e2e-binaries
80
+ cover-e2e-binaries : # # - Build binaries for the test-e2e target with the go 1.20+ cover flag
81
+ SNAPSHOT=true $(MAKE ) $(COVER_TARGETS )
82
+
83
+ .PHONY : $(COVER_TARGETS )
84
+ $(COVER_TARGETS ) : cover-% : # # - Build a binary with the -cover flag for integration testing
85
+ @mkdir -p build/cover
86
+ $(eval $@ _OS := $(firstword $(subst /, ,$(lastword $(subst cover-, ,$@ ) ) ) ) )
87
+ $(eval $@ _GO_ARCH := $(lastword $(subst /, ,$(lastword $(subst cover-, ,$@ ) ) ) ) )
88
+ $(eval $@ _ARCH := $(TARGET_ARCH_$($@ _GO_ARCH) ) )
89
+ $(eval $@ _BUILDMODE:= $(BUILDMODE_$($@ _OS) _$($@ _GO_ARCH) ) )
90
+ GOOS=$($@ _OS) GOARCH=$($@ _GO_ARCH) go build $(if $(DEV ) ,-tags="dev",) -cover -coverpkg=./... -gcflags=" ${GCFLAGS} " -ldflags=" ${LDFLAGS} " $($@ _BUILDMODE) -o build/cover/fleet-server-$(VERSION ) -$($@ _OS) -$($@ _ARCH) /fleet-server$(if $(filter windows,$($@ _OS) ) ,.exe,) .
91
+
78
92
.PHONY : clean
79
93
clean : # # - Clean up build artifacts
80
94
@printf " ${CMD_COLOR_ON} Clean up build artifacts\n${CMD_COLOR_OFF} "
81
- rm -rf .service_token ./bin/ ./build/
95
+ rm -rf .service_token .kibana_service_token . /bin/ ./build/
82
96
83
97
.PHONY : generate
84
98
generate : # # - Generate schema models
@@ -221,7 +235,11 @@ build-releaser: ## - Build a Docker image to run make package including all buil
221
235
222
236
.PHONY : docker-release
223
237
docker-release : build-releaser # # - Builds a release for all platforms in a dockerised environment
224
- docker run --rm -u $(shell id -u) :$(shell id -g) --volume $(PWD ) :/go/src/github.com/elastic/fleet-server $(BUILDER_IMAGE )
238
+ docker run --rm -u $(shell id -u) :$(shell id -g) --volume $(PWD ) :/go/src/github.com/elastic/fleet-server $(BUILDER_IMAGE ) release
239
+
240
+ .PHONY : docker-cover-e2e-binaries
241
+ docker-cover-e2e-binaries : build-releaser
242
+ docker run --rm -u $(shell id -u) :$(shell id -g) --volume $(PWD ) :/go/src/github.com/elastic/fleet-server $(BUILDER_IMAGE ) cover-e2e-binaries
225
243
226
244
.PHONY : release
227
245
release : $(PLATFORM_TARGETS ) # # - Builds a release. Specify exact platform with PLATFORMS env.
@@ -263,7 +281,7 @@ export $(shell sed 's/=.*//' ./dev-tools/integration/.env)
263
281
# Start ES with docker without waiting
264
282
.PHONY : int-docker-start-async
265
283
int-docker-start-async :
266
- @docker- compose -f ./dev-tools/integration/docker-compose.yml --env-file ./dev-tools/integration/.env up -d --remove-orphans elasticsearch
284
+ @docker compose -f ./dev-tools/integration/docker-compose.yml --env-file ./dev-tools/integration/.env up -d --remove-orphans elasticsearch
267
285
268
286
# Wait for ES to be ready
269
287
.PHONY : int-docker-wait
@@ -279,7 +297,8 @@ int-docker-start: ## - Start docker envronment for integration tests and wait un
279
297
# Stop integration docker setup
280
298
.PHONY : int-docker-stop
281
299
int-docker-stop : # # - Stop docker environment for integration tests
282
- @docker-compose -f ./dev-tools/integration/docker-compose.yml --env-file ./dev-tools/integration/.env down
300
+ @docker compose -f ./dev-tools/integration/docker-compose.yml --env-file ./dev-tools/integration/.env down
301
+ @rm -f .service_token
283
302
284
303
# Run integration tests with starting/stopping docker
285
304
.PHONY : test-int
@@ -300,6 +319,48 @@ test-int-set: ## - Run integration tests without setup
300
319
ELASTICSEARCH_HOSTS=${TEST_ELASTICSEARCH_HOSTS} ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME} ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD} \
301
320
go test -v -tags=integration -count=1 -race -p 1 ./...
302
321
322
+ # #################################################
323
+ # e2e testing targets
324
+ # #################################################
325
+
326
+ # based off build-and-push-cloud-image
327
+ .PHONY : build-e2e-agent-image
328
+ build-e2e-agent-image : docker-cover-e2e-binaries # # - Build a custom elastic-agent image with fleet-server binaries with coverage enabled injected
329
+ @printf " ${CMD_COLOR_ON} Creating test e2e agent image\n${CMD_COLOR_OFF} "
330
+ GOARCH=amd64 ./dev-tools/e2e/build.sh
331
+
332
+ .PHONY : e2e-certs
333
+ e2e-certs : # # - Use openssl to create a CA, encrypted private key, and signed fleet-server cert testing purposes
334
+ @printf " ${CMD_COLOR_ON} Creating test e2e certs\n${CMD_COLOR_OFF} "
335
+ @./dev-tools/e2e/certs.sh
336
+
337
+ .PHONY : e2e-docker-start
338
+ e2e-docker-start : int-docker-start # # - Start a testing instance of Elasticsearch and Kibana in docker containers
339
+ @KIBANA_TOKEN=$(shell ./dev-tools/e2e/get-kibana-servicetoken.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@${TEST_ELASTICSEARCH_HOSTS}) docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env up -d --remove-orphans kibana
340
+ @./dev-tools/e2e/wait-for-kibana.sh ${ELASTICSEARCH_USERNAME} :${ELASTICSEARCH_PASSWORD} @localhost:5601
341
+
342
+ .PHONY : e2e-docker-stop
343
+ e2e-docker-stop : # # - Tear down testing Elasticsearch and Kibana instances
344
+ @KIBANA_TOKEN=" supress-warning" docker compose -f ./dev-tools/e2e/docker-compose.yml --env-file ./dev-tools/integration/.env down
345
+ rm -f .kibana_service_token
346
+ @$(MAKE ) int-docker-stop
347
+
348
+ .PHONY : test-e2e
349
+ test-e2e : docker-cover-e2e-binaries build-e2e-agent-image e2e-certs # # - Setup and run the blackbox end to end test suite
350
+ @mkdir -p build/e2e-cover
351
+ @$(MAKE ) e2e-docker-start
352
+ @set -o pipefail; $(MAKE ) test-e2e-set | tee build/test-e2e.out
353
+ @$(MAKE ) e2e-docker-stop
354
+
355
+ .PHONY : test-e2e-set
356
+ test-e2e-set : # # - Run the blackbox end to end tests without setup.
357
+ cd testing; \
358
+ ELASTICSEARCH_SERVICE_TOKEN=$(shell ./dev-tools/integration/get-elasticsearch-servicetoken.sh ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}@${TEST_ELASTICSEARCH_HOSTS}) \
359
+ ELASTICSEARCH_HOSTS=${TEST_ELASTICSEARCH_HOSTS} ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME} ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD} \
360
+ AGENT_E2E_IMAGE=$(shell cat "build/e2e-image") \
361
+ CGO_ENABLED=1 \
362
+ go test -v -tags=e2e -count=1 -race -p 1 ./...
363
+
303
364
# #################################################
304
365
# Cloud testing targets
305
366
# #################################################
0 commit comments