-
Notifications
You must be signed in to change notification settings - Fork 211
PMM-7 API tests rework #5299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
PMM-7 API tests rework #5299
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5f166d9
PMM-7 Fix API tests
maxkondr ef171ec
update GH workflow
maxkondr 8bbe1ca
Merge branch 'v3' into PMM-7-API-tests-rework
maxkondr 4fc661c
Fix user snooze test
maxkondr bb594be
fix tests
maxkondr ff0ab8f
Merge branch 'v3' into PMM-7-API-tests-rework
maxkondr 0d997ce
Merge remote-tracking branch 'refs/remotes/origin/PMM-7-API-tests-rew…
maxkondr 71888b7
Fix
maxkondr 111a8ca
Merge branch 'v3' into PMM-7-API-tests-rework
maxkondr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /bin/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,25 @@ | ||
| # This Dockerfile is used only for API tests. | ||
| ARG VERSION=dev | ||
| ARG GIT_COMMIT=unknown | ||
| ARG BUILD_TIME=unknown | ||
| ARG GO_VERSION="1.25" | ||
| ARG GO_BASE_IMAGE="golang:${GO_VERSION}" | ||
|
|
||
| FROM golang:1.25 | ||
| FROM $GO_BASE_IMAGE AS builder | ||
| ENV GONOPROXY='github.com/percona,github.com/Percona-Lab' | ||
| ENV GONOSUMDB='github.com/percona,github.com/Percona-Lab' | ||
| ENV GOPRIVATE='github.com/percona,github.com/Percona-Lab' | ||
|
|
||
| RUN export GOPATH=$(go env GOPATH) && \ | ||
| mkdir -p $GOPATH/pmm | ||
| WORKDIR $GOPATH/pmm | ||
|
|
||
| COPY . $GOPATH/pmm/ | ||
| COPY go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
|
||
| COPY . $GOPATH/pmm | ||
| WORKDIR $GOPATH/pmm/api-tests/ | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| make -j4 init | ||
|
|
||
| CMD ["make", "init", "run-race"] | ||
| CMD ["make", "test-report"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,93 @@ | ||
| all: build | ||
| .DEFAULT_GOAL := help | ||
| BIN_DIR := $(CURDIR)/bin | ||
|
|
||
| init: ## Installs development tools | ||
| # --- Go-related variables ---------------------------------------------------------------- | ||
| GO_VERSION := $(shell grep '^go ' $(CURDIR)/../go.mod | awk '{print $$2}') | ||
|
|
||
| # --- Git variables ------------------------------------------------------------------------ | ||
| GIT_VERSION := $(shell git describe --tags) | ||
| GIT_COMMIT := $(shell git rev-parse --short HEAD) | ||
| BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) | ||
|
|
||
| # --- Test-related variables -------------------------------------------------------------- | ||
| TEST_DIRS := $(shell find . -type f -name '*_test.go' -not -path '*/.*' -exec dirname {} + | sort -u) | ||
| TEST_BINARY_TARGETS := $(subst /,-,$(subst ./,,$(TEST_DIRS))) | ||
| RUN_TEST_TARGETS := $(addprefix test-,$(TEST_BINARY_TARGETS)) | ||
| # Exclude server-settings tests from this list, as they require special handling (Grafana restart). | ||
| RUN_TEST_TARGETS := $(filter-out test-server-settings%,$(RUN_TEST_TARGETS)) | ||
| REPORT_OUT := pmm-api-tests-junit-report.xml | ||
| TEST_OUTPUT_PREFIX := pmm-api-tests-output | ||
| TEST_FLAGS := -test.count=1 -test.v | ||
|
|
||
| # --- Docker related variables ----------------------------------------------------------- | ||
| DOCKER_IMAGE := local/pmm-api-tests | ||
| PMM_SERVER_INSECURE_TLS ?= 1 | ||
| PMM_RUN_UPDATE_TEST ?= 0 | ||
| PMM_RUN_ADVISOR_TESTS ?= 0 | ||
|
|
||
| .PHONY: help guard-% init $(TEST_BINARY_TARGETS) $(RUN_TEST_TARGETS) | ||
| .PHONY: test-server-settings test test-report clean docker-build-image docker-run-tests | ||
|
|
||
| help: ## Show available targets | ||
| @echo "Available targets: $(TARGETS)" | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
maxkondr marked this conversation as resolved.
Outdated
|
||
|
|
||
| guard-%: | ||
| @[ -n "${$*}" ] || (echo "ERROR: $* is not set"; exit 1) | ||
|
|
||
| $(TEST_BINARY_TARGETS): ## Build test binaries | ||
| @dir="$(subst -,/,$@)"; \ | ||
| echo "-> Building test binary for dir: $$dir"; \ | ||
| go test -c -v -race -o $(BIN_DIR)/$@ $(CURDIR)/$$dir | ||
|
|
||
| init: $(TEST_BINARY_TARGETS) ## Installs development tools | ||
| @echo "-> Installing tools" | ||
| cd tools && go generate -x -tags=tools | ||
|
|
||
| build: | ||
| go install -v ./... | ||
| go test -c -v ./alerting | ||
| go test -c -v ./backup | ||
| go test -c -v ./inventory | ||
| go test -c -v ./management | ||
| go test -c -v ./server | ||
| go test -c -v ./user | ||
|
|
||
| run: | ||
| go test -count=1 -p 1 -v ./... 2>&1 | tee pmm-api-tests-output.txt | ||
| cat pmm-api-tests-output.txt | bin/go-junit-report > pmm-api-tests-junit-report.xml | ||
|
|
||
| run-dev: | ||
| go test -count=1 -p 1 -v ./... | ||
|
|
||
| run-race: | ||
| go test -count=1 -p 1 -v -race ./... 2>&1 | tee pmm-api-tests-output.txt | ||
| cat pmm-api-tests-output.txt | bin/go-junit-report > pmm-api-tests-junit-report.xml | ||
|
|
||
| clean: | ||
| rm -f ./pmm-api-tests-output.txt | ||
| rm -f ./pmm-api-tests-junit-report.xml | ||
| $(RUN_TEST_TARGETS): | ||
| @binary="$(subst test-,,$@)"; \ | ||
| echo "🚀 Run $$binary tests"; \ | ||
| $(BIN_DIR)/$$binary $(TEST_FLAGS) 2>&1 | tee $(TEST_OUTPUT_PREFIX)-$@.txt | ||
|
|
||
| # This target shall be running separately from the rest of tests, | ||
| # as it triggers Grafana restart that may cause other tests to fail. | ||
| test-server-settings: guard-PMM_SERVER_URL ## Run server-settings tests (requires Grafana restart) | ||
| @binary="$(subst test-,,$@)"; \ | ||
| echo "🚀 Run $$binary tests"; \ | ||
| $(BIN_DIR)/$$binary $(TEST_FLAGS) 2>&1 | tee $(TEST_OUTPUT_PREFIX)-$@.txt | ||
|
|
||
| test: guard-PMM_SERVER_URL $(RUN_TEST_TARGETS) ## Run tests | ||
| $(MAKE) test-server-settings | ||
| @echo "✅ All tests completed." | ||
|
|
||
| test-report: test ## Run tests and generate JUnit report | ||
| cat $(CURDIR)/$(TEST_OUTPUT_PREFIX)-*.txt | $(BIN_DIR)/go-junit-report > $(REPORT_OUT) | ||
| @echo "✅ Report is generated: $(REPORT_OUT)." | ||
|
maxkondr marked this conversation as resolved.
Outdated
|
||
|
|
||
| clean: ## Cleanup reports | ||
| rm -f $(CURDIR)/pmm-api-tests-*.txt | ||
| rm -f $(CURDIR)/$(REPORT_OUT) | ||
| @echo "✅ Cleanup completed." | ||
|
|
||
| ## Docker-related targets | ||
|
|
||
| docker-build-image: ## Build Docker image with tests | ||
| docker build \ | ||
| -f Dockerfile \ | ||
| --build-arg GO_VERSION=$(GO_VERSION) \ | ||
| --build-arg VERSION=$(GIT_VERSION) \ | ||
| --build-arg GIT_COMMIT=$(GIT_COMMIT) \ | ||
| --build-arg BUILD_TIME=$(BUILD_TIME) \ | ||
| -t $(DOCKER_IMAGE) ../ | ||
| @echo "✅ Docker image '$(DOCKER_IMAGE)' built successfully." | ||
|
|
||
| docker-run-tests: guard-PMM_SERVER_URL ## Run tests inside Docker container | ||
| docker run \ | ||
| -e PMM_SERVER_URL=$(PMM_SERVER_URL) \ | ||
| -e PMM_SERVER_INSECURE_TLS=$(PMM_SERVER_INSECURE_TLS) \ | ||
| -e PMM_RUN_UPDATE_TEST=$(PMM_RUN_UPDATE_TEST) \ | ||
| -e PMM_RUN_ADVISOR_TESTS=$(PMM_RUN_ADVISOR_TESTS) \ | ||
| --name api-tests \ | ||
| --network host \ | ||
| $(DOCKER_IMAGE) | ||
| @echo "✅ Tests executed successfully inside Docker container." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.