testing

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Content added in v0.11.4

func Content(t *testing.T, urn string) []byte

func NoError

func NoError(t *testing.T) func(error)

NoError returns a helper as an error handler to check no error occurred.

See SetEnvs' example.

func SetEnvs

func SetEnvs(handle func(error), vars ...env.Variable) (func(func(error)), error)

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

func StrictNoError(t *testing.T) func(error)

StrictNoError returns a helper as a strict error handler to check no error occurred.

See SetEnvs' example.

func WithDeadline

func WithDeadline(parent context.Context, src interface{}, delta time.Duration) (context.Context, context.CancelFunc)

Types

This section is empty.

Jump to

Keyboard shortcuts

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