Documentation ¶
Overview ¶
Package testing extends the built-in package and provides a set of helpers to make the test process more comfortable. For example
- use SetEnvs to change environment variables safely to test your twelve-factor application.
Index ¶
- func Content(t *testing.T, urn string) []byte
- func NoError(t *testing.T) func(error)
- func SetEnvs(handle func(error), vars ...env.Variable) (func(func(error)), error)
- func StrictNoError(t *testing.T) func(error)
- func WithDeadline(parent context.Context, src interface{}, delta time.Duration) (context.Context, context.CancelFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoError ¶
NoError returns a helper as an error handler to check no error occurred.
See SetEnvs' example.
func SetEnvs ¶
SetEnvs allows changing environment variables concurrently.
import( "os" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.octolab.org/env" . "go.octolab.org/testing" ) func Test(t *testing.T) { t.Run("case 1", func(t *testing.T) { t.Parallel() release, err := SetEnvs(NoError(t), env.Must(env.GoTraceback, "system")) require.NoError(t, err) assert.Equal(t, "system", os.Getenv(env.GoTraceback)) release(StrictNoError(t)) }) t.Run("case 2", func(t *testing.T) { t.Parallel() release, err := SetEnvs(NoError(t), env.Must(env.GoTraceback, "crash")) require.NoError(t, err) assert.Equal(t, "crash", os.Getenv(env.GoTraceback)) release(StrictNoError(t)) }) }
func StrictNoError ¶
StrictNoError returns a helper as a strict error handler to check no error occurred.
See SetEnvs' example.
func WithDeadline ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.