From e7a4d9f180dba91725d61a5896d7c76ca44f0631 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 2 Jul 2025 22:41:25 +0200 Subject: [PATCH] Allow filtering tests from mage (#1072) --- AGENTS.md | 4 ++-- magefile.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5d235f87b..7880b83b7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,9 +15,9 @@ The project consists of: ### Backend (Go) - **Build**: `mage build` - Builds the Go binary -- **Test**: `mage test:feature` - Runs feature tests +- **Test Features**: `mage test:feature` - Runs feature tests - **Test Web**: `mage test:web` - Runs web tests -- **Test All**: `mage test:all` - Runs all tests +- You can run specific tests with `mage test:filter ` where `` is a go test filter string. - **Lint**: `mage lint` - Runs golangci-lint - **Lint Fix**: `mage lint:fix` - Runs golangci-lint with auto-fix - **Generate Swagger Docs**: `mage generate:swagger-docs` - Updates API documentation (Generally you won't need to run this unless the user tells you to. It is updated automatically in the CI workflow) diff --git a/magefile.go b/magefile.go index 380e25a2f..ce34a526e 100644 --- a/magefile.go +++ b/magefile.go @@ -396,7 +396,16 @@ func (Test) Coverage() { func (Test) Web() { mg.Deps(initVars) // We run everything sequentially and not in parallel to prevent issues with real test databases - runAndStreamOutput("go", "test", Goflags[0], "-p", "1", "-timeout", "45m", PACKAGE+"/pkg/webtests") + args := []string{"test", Goflags[0], "-p", "1", "-timeout", "45m", PACKAGE + "/pkg/webtests"} + runAndStreamOutput("go", args...) +} + +func (Test) Filter(filter string) { + mg.Deps(initVars) + setApiPackages() + // We run everything sequentially and not in parallel to prevent issues with real test databases + args := append([]string{"test", Goflags[0], "-p", "1", "-timeout", "45m", "-run", filter}, ApiPackages...) + runAndStreamOutput("go", args...) } func (Test) All() {