From 75c05aeb3fd1d6082d0d7cb49928bc463e417c55 Mon Sep 17 00:00:00 2001 From: Konstantin Sykulev Date: Tue, 3 Mar 2026 16:01:11 -0600 Subject: [PATCH] adding gotestsum for better test output (#40753) **Related issue:** Resolves #30896 ## Testing - [x] QA'd all new/changed functionality manually --- .github/workflows/test-go-suite.yaml | 15 ++++++++++++++- .github/workflows/test-go.yaml | 16 ++++++++++++++-- Makefile | 5 +++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-go-suite.yaml b/.github/workflows/test-go-suite.yaml index 977a10adad..04393a8a2c 100644 --- a/.github/workflows/test-go-suite.yaml +++ b/.github/workflows/test-go-suite.yaml @@ -115,6 +115,9 @@ jobs: with: go-version-file: 'go.mod' + - name: Install gotestsum + run: go install gotest.tools/gotestsum@latest + # Pre-starting dependencies here means they are ready to go when we need them. - name: Start Infra Dependencies if: ${{ env.NEED_DOCKER }} @@ -230,7 +233,9 @@ jobs: - name: Run Go Tests run: | - GO_TEST_EXTRA_FLAGS="-v -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT ${{ env.RUN_TESTS_ARG }}" \ + USE_GOTESTSUM=1 \ + GOTESTSUM_FORMAT=testdox \ + GO_TEST_EXTRA_FLAGS="-v -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT ${{ env.RUN_TESTS_ARG }}" \ TEST_LOCK_FILE_PATH=$(pwd)/lock \ TEST_CRON_NO_RECOVER=1 \ NETWORK_TEST=1 \ @@ -298,6 +303,14 @@ jobs: name: ${{ env.ARTIFACT_PREFIX }}-summary-test-log path: /tmp/summary.txt + - name: Upload JSON test output + if: always() + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + with: + name: ${{ env.ARTIFACT_PREFIX }}-test-json + path: /tmp/test-output.json + if-no-files-found: warn + - name: Set test status if: always() run: | diff --git a/.github/workflows/test-go.yaml b/.github/workflows/test-go.yaml index 8229895148..36d8e5c627 100644 --- a/.github/workflows/test-go.yaml +++ b/.github/workflows/test-go.yaml @@ -128,6 +128,9 @@ jobs: with: go-version-file: 'go.mod' + - name: Install gotestsum + run: go install gotest.tools/gotestsum@latest + - name: verify mysql run: | while ! mysqladmin ping --host=localhost --port=$PORT --protocol=TCP --silent; do @@ -144,9 +147,10 @@ jobs: - name: Run Go tests run: | - go test -v -parallel 8 -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT \ + gotestsum --format=testdox --jsonfile=/tmp/test-output.json -- \ + -v -parallel 8 -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT \ -coverprofile=coverage.txt -covermode=atomic -coverpkg=github.com/fleetdm/fleet/v4/server/mdm/nanomdm/... \ - ./server/mdm/nanomdm/storage/mysql 2>&1 | tee /tmp/gotest.log + ./server/mdm/nanomdm/storage/mysql 2>&1 | tee /tmp/gotest.log - name: Save coverage uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 @@ -198,6 +202,14 @@ jobs: name: nanomdm-summary-test-log path: /tmp/summary.txt + - name: Upload JSON test output + if: always() + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 + with: + name: nanomdm-test-json + path: /tmp/test-output.json + if-no-files-found: warn + # We upload all backend coverage in one step so that we're less like to end up in a situation with a partial coverage report. upload-coverage: needs: [test-go-no-db, test-go, test-go-extended-mysql, test-go-nanomdm] diff --git a/Makefile b/Makefile index 2ca1ed02a6..eb05771071 100644 --- a/Makefile +++ b/Makefile @@ -267,10 +267,15 @@ dlv_test_pkg_to_test := $(addprefix github.com/fleetdm/fleet/v4/,$(PKG_TO_TEST)) .run-go-tests: ifeq ($(PKG_TO_TEST), "") @echo "Please specify one or more packages to test. See '$(TOOL_CMD) help run-go-tests' for more info."; +else +ifdef USE_GOTESTSUM + @echo Running Go tests with gotestsum: + gotestsum --format=$(GOTESTSUM_FORMAT) --jsonfile=/tmp/test-output.json -- -tags full,fts5,netgo -run=${TESTS_TO_RUN} ${GO_TEST_MAKE_FLAGS} ${GO_TEST_EXTRA_FLAGS} -parallel 8 -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(COVER_PKG) $(go_test_pkg_to_test) else @echo Running Go tests with command: go test -tags full,fts5,netgo -run=${TESTS_TO_RUN} ${GO_TEST_MAKE_FLAGS} ${GO_TEST_EXTRA_FLAGS} -parallel 8 -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(COVER_PKG) $(go_test_pkg_to_test) endif +endif # This is the base command to debug Go tests. # Wrap this to run tests with presets (see `debug-go-tests`)