From 6d29119128d3db8ae68e642d67720eb828f27a22 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 31 Aug 2024 12:22:09 +0200 Subject: [PATCH 1/2] chore: use gotestsum as testrunner --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1847d01..b53056f 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ $(eval BUILD_TIME=$(shell date -u '+%Y-%m-%d_%I:%M:%S%p')) GO_LDFLAGS :=" -X main.Version=${BRANCH_NAME} -X main.CompiledBy=${COMPILED_BY} -X main.GitCommit=${GIT_COMMIT} -X main.Branch=${BRANCH_NAME} -X main.BuildTime=${BUILD_TIME}" +export TEST_RUNNER=$(GOBIN)/gotestsum export LINTER=$(GOBIN)/golangci-lint export LINTERCMD=run --no-config -v \ --print-linter-name \ @@ -55,6 +56,9 @@ install-metalinter: @$(GO) get -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 @$(GO) install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2 +install-testrunner: + @$(GO) install -v gotest.tools/gotestsum@latest + install-yamlls: npm install --global yaml-language-server @@ -65,7 +69,8 @@ integration-test-deps: test: $(MAKE) integration-test-deps - @$(GO) test ./... -v -race -tags=integration + $$(command -v $(TEST_RUNNER)) || { echo "gotestsum command not found! Installing..." && $(MAKE) install-testrunner; }; + @$(TEST_RUNNER) ./... -v -race -tags=integration coverage: @$(GO) test -coverprofile=.coverage -tags=integration -coverpkg=./internal/... ./internal/... && go tool cover -html=.coverage From d6697a1c990c50cf112a4c5b42440935c2d1f047 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 27 Oct 2024 20:07:28 +0100 Subject: [PATCH 2/2] fix: only use gotestsum in ci or if installed --- .github/workflows/tests.yml | 3 +++ Makefile | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c6ed7de..8b1977b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,5 +23,8 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Install testrunner + run: make install-testrunner + - name: Run tests run: make test diff --git a/Makefile b/Makefile index b53056f..ff1cae5 100644 --- a/Makefile +++ b/Makefile @@ -69,8 +69,10 @@ integration-test-deps: test: $(MAKE) integration-test-deps - $$(command -v $(TEST_RUNNER)) || { echo "gotestsum command not found! Installing..." && $(MAKE) install-testrunner; }; - @$(TEST_RUNNER) ./... -v -race -tags=integration + @$(TEST_RUNNER) ./... -v -race -tags=integration || { \ + echo "gotestsum command not found or failed! Falling back to 'go test'..."; \ + $(GO) test ./... -v -race -tags=integration; \ + } coverage: @$(GO) test -coverprofile=.coverage -tags=integration -coverpkg=./internal/... ./internal/... && go tool cover -html=.coverage