Skip to content

Commit

Permalink
Try splitting tests up
Browse files Browse the repository at this point in the history
  • Loading branch information
dantecatalfamo committed Jan 8, 2025
1 parent 8d09035 commit 33223eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
test-go:
strategy:
matrix:
suite: ["integration", "core"]
suite: ["integration", "core", "migration", "fleetctl", "vuln"]
os: [ubuntu-latest]
mysql: ["mysql:8.0.36", "mysql:8.4.3", "mysql:9.1.0"] # make sure to update supported versions docs when this changes
isCron:
Expand Down Expand Up @@ -118,11 +118,15 @@ jobs:
- name: Run Go Tests
run: |
if [[ "${{ matrix.suite }}" == "core" ]]; then
RUN_TESTS_ARG='-skip=^TestIntegrations'
CI_TEST_PKG=main RUN_TESTS_ARG='-skip=^TestIntegrations'
elif [[ "${{ matrix.suite }}" == "integration" ]]; then
RUN_TESTS_ARG='-run=^TestIntegrations'
else
RUN_TESTS_ARG=''
CI_TEST_PKG=main RUN_TESTS_ARG='-run=^TestIntegrations'
elif [[ "${{ matrix.suite }}" == "fleetctl" ]]; then
CI_TEST_PKG=fleetctl RUN_TESTS_ARG=''
elif [[ "${{ matrix.suite }}" == "migration" ]]; then
CI_TEST_PKG=migration RUN_TESTS_ARG=''
elif [[ "${{ matrix.suite }}" == "vuln" ]]; then
CI_TEST_PKG=vuln RUN_TESTS_ARG=''
fi
GO_TEST_EXTRA_FLAGS="-v -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT $RUN_TESTS_ARG" \
TEST_LOCK_FILE_PATH=$(pwd)/lock \
Expand Down
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,30 @@ dump-test-schema:
# TESTS_TO_RUN: Name specific tests to run in the specified packages. Leave blank to run all tests in the specified packages.
# GO_TEST_EXTRA_FLAGS: Used to specify other arguments to `go test`.
# GO_TEST_MAKE_FLAGS: Internal var used by other targets to add arguments to `go test`.
#
#
PKG_TO_TEST := "" # default to empty string; can be overridden on command line.
go_test_pkg_to_test := $(addprefix ./,$(PKG_TO_TEST)) # set paths for packages to test
dlv_test_pkg_to_test := $(addprefix github.com/fleetdm/fleet/v4/,$(PKG_TO_TEST)) # set URIs for packages to debug

DEFAULT_PKG_TO_TEST := ./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/...
ifeq ($(CI_TEST_PKG), main)
CI_PKG_TO_TEST=$(shell go list ${DEFAULT_PKG_TO_TEST} | sed -e 's|github.com/fleetdm/fleet/v4/||g')
else ifeq ($(CI_TEST_PKG), migration)
CI_PKG_TO_TEST="server/datastore/mysql/migrations/..."
else ifeq ($(CI_TEST_PKG), fleetctl)
CI_PKG_TO_TEST="cmd/fleetctl/..."
else ifeq ($(CI_TEST_PKG), vuln)
CI_PKG_TO_TEST="server/vulnerabilities/..."
else
CI_PKG_TO_TEST=$(DEFAULT_PKG_TO_TEST)
endif

ci-pkg:
@echo $(CI_PKG_TO_TEST)

.run-go-tests:
ifeq ($(PKG_TO_TEST), "")
@echo "Please specify one or more packages to test with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
@echo "Please specify one or more packages to test with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
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=github.com/fleetdm/fleet/v4/... $(go_test_pkg_to_test)
Expand All @@ -171,22 +187,22 @@ endif
# GO_TEST_EXTRA_FLAGS: Used to specify other arguments to `go test`.
.debug-go-tests:
ifeq ($(PKG_TO_TEST), "")
@echo "Please specify one or more packages to debug with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
@echo "Please specify one or more packages to debug with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
else
@echo Debugging tests with command:
dlv test ${dlv_test_pkg_to_test} --api-version=2 --listen=127.0.0.1:61179 ${DEBUG_TEST_EXTRA_FLAGS} -- -test.v -test.run=${TESTS_TO_RUN} ${GO_TEST_EXTRA_FLAGS}
dlv test ${dlv_test_pkg_to_test} --api-version=2 --listen=127.0.0.1:61179 ${DEBUG_TEST_EXTRA_FLAGS} -- -test.v -test.run=${TESTS_TO_RUN} ${GO_TEST_EXTRA_FLAGS}
endif

# Command to run specific tests in development. Can run all tests for one or more packages, or specific tests within packages.
run-go-tests:
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .run-go-tests GO_TEST_MAKE_FLAGS="-v"

debug-go-tests:
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .debug-go-tests
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .debug-go-tests

# Command used in CI to run all tests.
test-go: dump-test-schema generate-mock
make .run-go-tests PKG_TO_TEST="./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/..."
test-go: # dump-test-schema generate-mock
make .run-go-tests PKG_TO_TEST="$(CI_PKG_TO_TEST)"

analyze-go:
go test -tags full,fts5,netgo -race -cover ./...
Expand Down

0 comments on commit 33223eb

Please sign in to comment.