https://github.com/crazy-max/gotestlist
List tests in the given Go packages
https://github.com/crazy-max/gotestlist
golang test
Last synced: about 1 year ago
JSON representation
List tests in the given Go packages
- Host: GitHub
- URL: https://github.com/crazy-max/gotestlist
- Owner: crazy-max
- License: mit
- Created: 2022-06-03T09:47:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-12T06:15:08.000Z (almost 2 years ago)
- Last Synced: 2024-10-18T07:32:15.341Z (over 1 year ago)
- Topics: golang, test
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/crazy-max/gotestlist)
[](https://github.com/crazy-max/gotestlist/actions?workflow=test)
[](https://goreportcard.com/report/github.com/crazy-max/gotestlist)
[](https://codecov.io/gh/crazy-max/gotestlist)
## About
List tests in the given Go packages.
## Installation
```console
$ go install github.com/crazy-max/gotestlist/cmd/gotestlist@latest
```
## Usage
```console
$ gotestlist .
gotestlist TestTests /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
```
```console
$ gotestlist ./...
gotestlist TestTests /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
main TestDirs /home/crazy/src/github.com/crazy-max/gotestlist/cmd/gotestlist/gotestlist_test.go
```
```console
$ gotestlist github.com/crazy-max/gotestlist
gotestlist TestTests /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
```
```console
$ gotestlist github.com/crazy-max/gotestlist/...
gotestlist TestTests /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
main TestDirs /home/crazy/src/github.com/crazy-max/gotestlist/cmd/gotestlist/gotestlist_test.go
```
```console
$ gotestlist github.com/crazy-max/gotestlist github.com/crazy-max/gotestlist/cmd/gotestlist
gotestlist TestTests /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
main TestDirs /home/crazy/src/github.com/crazy-max/gotestlist/cmd/gotestlist/gotestlist_test.go
```
```console
$ gotestlist -f json ./... | jq
[
{
"name": "TestTests",
"benchmark": false,
"fuzz": false,
"suite": "",
"file": "/home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go",
"pkg": "gotestlist"
},
{
"name": "TestDirs",
"benchmark": false,
"fuzz": false,
"suite": "",
"file": "/home/crazy/src/github.com/crazy-max/gotestlist/cmd/gotestlist/gotestlist_test.go",
"pkg": "main"
}
]
```
```console
$ gotestlist -f "Pkg: {{.Pkg}} | TestName: {{.Name}} | File: {{.File}}" ./...
Pkg: gotestlist | TestName: TestTests | File: /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
Pkg: main | TestName: TestDirs | File: /home/crazy/src/github.com/crazy-max/gotestlist/cmd/gotestlist/gotestlist_test.go
```
```console
$ gotestlist -d 1 ./...
["TestDirs|TestTests"]
```
```console
$ gotestlist -d 2 ./...
["TestDirs","TestTests"]
```
### Distribute tests with GitHub Actions
`-d `flag dynamically distributes the tests based on the given matrix size and
number of tests found. This JSON output can then be used as [matrix input](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs)
in a GitHub Action workflow:
```yaml
name: test
on:
push:
env:
GO_VERSION: 1.23
jobs:
test-prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.tests.outputs.matrix }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
-
name: Install gotestlist
run:
go install github.com/crazy-max/gotestlist/cmd/gotestlist@latest
-
name: Create matrix
id: tests
run: |
matrix="$(gotestlist -d 4 ./...)"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
test:
runs-on: ubuntu-latest
needs:
- test-prepare
strategy:
fail-fast: false
test: ${{ fromJson(needs.test-prepare.outputs.matrix) }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
-
name: Test
run: |
go test -run=(${{ matrix.test }})/ -coverprofile=coverage.txt -covermode=atomic ./...
-
name: Upload coverage
uses: codecov/codecov-action@v5
with:
files: ./coverage.txt
```
This is useful if you have a lot of tests, and you want to distribute them to
reduce build time.
## Contributing
Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You
can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) or by making
a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely!
Thanks again for your support, it is much appreciated! :pray:
## License
MIT. See `LICENSE` for more details.