Code Monkey home page Code Monkey logo

gotestlist's Introduction

PkgGoDev Test workflow Go Report Codecov

About

List tests in the given Go packages.

Installation

$ go install github.com/crazy-max/gotestlist/cmd/gotestlist@latest

Usage

$ gotestlist .
gotestlist     TestTests     /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
$ 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
$ gotestlist github.com/crazy-max/gotestlist
gotestlist     TestTests     /home/crazy/src/github.com/crazy-max/gotestlist/gotestlist_test.go
$ 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
$ 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
$ 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"
  }
]
$ 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
$ gotestlist -d 1 ./...
["TestDirs|TestTests"]
$ 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 in a GitHub Action workflow:

name: test

on:
  push:

env:
  GO_VERSION: 1.20

jobs:
  test-prepare:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.tests.outputs.matrix }}
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Set up Go
        uses: actions/setup-go@v4
        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@v3
      -
        name: Set up Go
        uses: actions/setup-go@v4
        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@v3
        with:
          file: ./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 or by making a Paypal donation to ensure this journey continues indefinitely!

Thanks again for your support, it is much appreciated! ๐Ÿ™

License

MIT. See LICENSE for more details.

gotestlist's People

Contributors

crazy-max avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

isgasho

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.