Skip to content
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

Add make commands to standardize running/debugging Go tests #24606

Merged
merged 9 commits into from
Dec 11, 2024

Conversation

sgress454
Copy link
Contributor

Checklist for submitter

  • Manual QA for all new/changed functionality

Details

This PR adds two new user-facing make targets:

  • run-go-tests: run Go tests for one or more packages, optionally filtering to specific tests
  • debug-go-tests: debug (using Delve) Go tests for one or more packages, optionally filtering to specific tests

Example usage:

# Run all tests in the mysql and gdmf packages
make run-go-tests PKG_TO_TEST="server/mdm/apple/gdmf server/datastore/mysql"
# Run all the TestMDMApple tests in the mysql package
make run-go-tests PKG_TO_TEST=server/datastore/mysql TESTS_TO_RUN="^TestMDMApple\$$" 
# Run only the TestMDMAppleProfileLabels test in the mysql package
make run-go-tests PKG_TO_TEST=server/datastore/mysql TESTS_TO_RUN="^TestMDMApple\$$/^TestMDMAppleProfileLabels\$$" 

Notes

Two new "private" targets .run-go-tests and .debug-go-tests were created as base commands for both test-go (used in CI) and the new user-facing commands.

Comment on lines -147 to -148
test-go: dump-test-schema generate-mock
go test -tags full,fts5,netgo ${GO_TEST_EXTRA_FLAGS_VAR} -parallel 8 -coverprofile=coverage.txt -covermode=atomic -coverpkg=github.com/fleetdm/fleet/v4/... ./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved a bunch of the boilerplate args into the base .run-go-tests target; see updates test-go target below

Comment on lines +188 to +189
test-go: dump-test-schema generate-mock
make .run-go-tests PKG_TO_TEST="./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/..."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the $GO_TEST_EXTRA_FLAGS var still works, so the existing make test-go usage will be unaffected

@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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like using the command line for dlv, but I know some folks use vscode, do we want to add a launch.json entry to connect to this?

        {
            "name": "Launch Remote",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "${workspaceFolder}",
            "port": 61179,
            "host": "localhost",
            "cwd": "${workspaceFolder}",
            "trace": "verbose"
         }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Attach to a running Fleet server" is in the current launch.json. It doesn't have verbose logging on, but I'm not sure I'd want to unilaterally add that in case anyone's used to the way it works now. Although in my experience debugging go in VSCode is extremely slow so there might not be too many people using it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I totally missed that entry 🤦 . I think "trace": "verbose" isn't necessary.

Copy link
Contributor

@ksykulev ksykulev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with these changes.

@sgress454 sgress454 merged commit bf7876a into main Dec 11, 2024
3 checks passed
@sgress454 sgress454 deleted the sgress454/add-easier-dev-testing branch December 11, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants