buckets

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2023 License: MIT Imports: 10 Imported by: 0

README

go-test-buckets

Actions Status Coverage Status PkgGoDev go-report

Split your go tests into buckets, or exclude some packages/directories.

Buckets

package main_test

import (
	"testing"
	"os"

	"github.com/Eun/go-test-buckets"
)

func TestMain(m *testing.M) {
	buckets.Buckets(m)
	os.Exit(m.Run())
}

// run with BUCKET=0 TOTAL_BUCKETS=2 go test -count=1 -v ./...
// will run TestA and TestB

// run with BUCKET=1 TOTAL_BUCKETS=2 go test -count=1 -v ./...
// will run TestC

func TestA(t *testing.T) {
}

func TestB(t *testing.T) {
}

func TestC(t *testing.T) {
}

Excluding Packages/Directories

  1. Add to your package
    func TestMain(m *testing.M) {
        buckets.Buckets(m)
        os.Exit(m.Run())
    }
    
  2. Run EXCLUDE_PACKAGES=package/path/to/exclude,package/path/to/exclude-2 go test -count=1 -v ./...
  3. Or EXCLUDE_DIRECTORIES=/full/path/to/exclude go test -count=1 -v ./...

Because of go test package separation, you have to call buckets.Buckets(m) in every package you want to ignore.

Why?

Speed up ci pipelines by parallelizing go tests without thinking about t.Parallel. And getting rid of weird piping go test $(go list ./... | grep -v /ignore/)

Extra Github Actions

You can use following github action when using test buckets:

on:
  push:

name: "push"
jobs:
  test:
    strategy:
      matrix:
        platform: [ubuntu-latest]
        bucket: [0, 1, 2, 3]
    env:
        TOTAL_BUCKETS: 4
    runs-on: ${{ matrix.platform }}
    steps:
      -
        name: Checkout code
        uses: actions/checkout@v3.5.2
      -
        name: Get go.mod details
        uses: Eun/go-mod-details@v1.0.6
        id: go-mod-details
      -
        name: Install Go
        uses: actions/setup-go@v4
        with:
          go-version: ${{ steps.go-mod-details.outputs.go_version }}
      -
        name: Test
        run: go test -v -count=1 ./...
        env:
          BUCKET: ${{ matrix.bucket }}

Documentation

Overview

Package buckets provides a way to separate go tests into buckets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Buckets

func Buckets(m *testing.M)

Buckets must be called to get the test bucket feature working. It will modify the tests present in the testing.M struct.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL