GitHunt
MA

matheusd/testctx

A Go module with useful functions for creating context.Context instances for tests.

testctx

testctx is a Go package with useful methods for simplifying creating test
contexts. The methods ensure a context created within a test is correctly
canceled once the test is completed, to avoid leaking any resources created
during the test.

Requiring this package

$ go get matheusd.com/testctx@latest

Example usage

package mypkg

import (
    "testing"

    "matheusd.com/testctx"
)

func testFunc(ctx context.Context) {
    <-ctx.Done()
}

func TestMyFunc(t *testing.T) {
    t.Parallel()
    testFunc(testctx.New(t))
    
    // testFunc gets GC'd once the test completes.
}

License

This package is licensed under the copyfree ISC License.

Languages

Go100.0%

Contributors

ISC License
Created December 6, 2022
Updated December 6, 2022
matheusd/testctx | GitHunt